std::ios_base::ios_base(const std::ios_base) is private - c++

FatalMessageAssembler is a class which collects messages to an inner stringstream variable via << operator. It prints message of result variable and terminates application by += operator. (I have reasons not to put it in a function)
Header:
class FatalMessageAssembler
{
public:
FatalMessageAssembler();
std::stringstream contents;
void operator+=(FatalMessageAssembler& result);
};
template<typename msg_type> FatalMessageAssembler& operator<<(FatalMessageAssembler& target,const msg_type msg);
namespace NLog
{
extern FatalMessageAssembler assembler;
}
Source:
FatalMessageAssembler::FatalMessageAssembler()
{
}
FatalMessageAssembler NLog::assembler=FatalMessageAssembler();
template<typename msg_type> FatalMessageAssembler& operator<<(FatalMessageAssembler& target, const msg_type msg)
{
target.contents<<msg;
return target;
}
void FatalMessageAssembler::operator+=(FatalMessageAssembler& result)
{
qFatal(result.contents.str().c_str());
result.contents.str("");//I'm not sre if qFatal() can be handled not to terminate app
result.contents.clear();
}
This create an error std::ios_base::ios_base(const std::ios_base) is private. I didn't forget reference in return type.
Full log:
06:36:41: Running steps for project tsl...
06:36:41: Configuration unchanged, skipping qmake step.
06:36:41: Starting: "/usr/bin/make"
g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I../tsl -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I. -I../tsl -I. -o servicelogger.o ../tsl/servicelogger.cpp
In file included from /usr/include/c++/4.8/ios:42:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/bits/ios_base.h: In copy constructor 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)':
/usr/include/c++/4.8/bits/ios_base.h:786:5: error: 'std::ios_base::ios_base(const std::ios_base&)' is private
ios_base(const ios_base&);
^
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from ../tsl/servicelogger.h:8:0,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/sstream: In copy constructor 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)':
/usr/include/c++/4.8/sstream:502:11: note: synthesized method 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' first required here
class basic_stringstream : public basic_iostream<_CharT, _Traits>
^
In file included from /usr/include/c++/4.8/ios:43:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/qt4/QtCore/qlist.h:50,
from /usr/include/qt4/QtCore/qobject.h:50,
from /usr/include/qt4/QtCore/QObject:1,
from ../tsl/servicelogger.h:5,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/streambuf: In copy constructor 'std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)':
/usr/include/c++/4.8/streambuf:802:7: error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]' is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from ../tsl/servicelogger.h:8:0,
from ../tsl/servicelogger.cpp:2:
/usr/include/c++/4.8/sstream:64:11: error: within this context
class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
^
/usr/include/c++/4.8/sstream: In copy constructor 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)':
/usr/include/c++/4.8/sstream:502:11: note: synthesized method 'std::basic_stringbuf<char>::basic_stringbuf(const std::basic_stringbuf<char>&)' first required here
class basic_stringstream : public basic_iostream<_CharT, _Traits>
^
In file included from ../tsl/servicelogger.cpp:2:0:
../tsl/servicelogger.h: In copy constructor 'FatalMessageAssembler::FatalMessageAssembler(const FatalMessageAssembler&)':
../tsl/servicelogger.h:39:7: note: synthesized method 'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)' first required here
class FatalMessageAssembler
^
../tsl/servicelogger.cpp: At global scope:
../tsl/servicelogger.cpp:47:61: note: synthesized method 'FatalMessageAssembler::FatalMessageAssembler(const FatalMessageAssembler&)' first required here
FatalMessageAssembler NLog::assembler=FatalMessageAssembler();
^
../tsl/servicelogger.cpp: In member function 'void FatalMessageAssembler::operator+=(FatalMessageAssembler&)':
../tsl/servicelogger.cpp:55:41: warning: format not a string literal and no format arguments [-Wformat-security]
qFatal(result.contents.str().c_str());
^
make: *** [servicelogger.o] Error 1
06:36:46: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project tsl (kit: Desktop)
When executing step "Make"
06:36:46: Elapsed time: 00:05.

FatalMessageAssembler NLog::assembler=FatalMessageAssembler();
This is the crucial line that causes the error. You can't copy streams, and thus you can't copy FatalMessageAssemblers1. However, the initialization with a temporary is actually not needed.
FatalMessageAssembler NLog::assembler;
Should also initialize assembler appropriately.
1) The move constructor of your class isn't implicitly declared because stringstream, the type of one of the members, is not copyable.

Related

make error: recipe for target 'all-recursive' failed

Hello and thank you for your help in advance (I'm a bit of a newbie). I am on ubuntu 18.
I am trying to install an older version of some software called HepMC (need older version for project) and I had no problem installing the slightly newer version. When I try to build from source I get an error on the make command. I've seen this "all-recurive failed" error all over the web, but the solutions I've seen for other people have seemed to be very software specific and have not helped me.
I am not really sure how to interpret this error and I haven't been able to find a good answer. Any tips or suspicions on what might be going on here would be greatly appreciated. Been bashing my head against this for awhile
Before running make I did
autoreconf -i configure.ac
./configure
and this ran with no errors or warnings.
Here's the snippet where the error seems to begin, I'll attach the full printout from "make" down below.
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:408:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenEvent.h:459:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:459:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:459:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
CommonIO.cc: In member function ‘HepMC::HeavyIon* HepMC::CommonIO::read_heavy_ion(std::istream*)’:
CommonIO.cc:318:9: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:328:26: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
if( nh == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::PdfInfo* HepMC::CommonIO::read_pdf_info(std::istream*)’:
CommonIO.cc:344:9: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:356:27: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
if( id1 == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenVertex* HepMC::CommonIO::read_vertex(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:374:9: warning: converting ‘false’ to pointer type ‘HepMC::GenVertex*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenParticle* HepMC::CommonIO::read_particle(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:411:9: warning: converting ‘false’ to pointer type ‘HepMC::GenParticle*’ [-Wconversion-null]
return false;
^~~~~
Makefile:478: recipe for target 'CommonIO.lo' failed
make[1]: *** [CommonIO.lo] Error 1
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
Makefile:397: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
and here's the full return of make
make
Making all in HepMC
make[1]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make all-am
make[2]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make[2]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/HepMC'
Making all in src
make[1]: Entering directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
/bin/bash ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I../HepMC -I.. -I.. -ansi -pedantic -Wall -g -O2 -MT CommonIO.lo -MD -MP -MF .deps/CommonIO.Tpo -c -o CommonIO.lo CommonIO.cc
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I../HepMC -I.. -I.. -ansi -pedantic -Wall -g -O2 -MT CommonIO.lo -MD -MP -MF .deps/CommonIO.Tpo -c CommonIO.cc -fPIC -DPIC -o .libs/CommonIO.o
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:173:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:173:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:173:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenVertex.h:237:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:237:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:237:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenVertex.h:307:64: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenVertex.h:307:64: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/GenEvent.h:123:0,
from ../HepMC/CommonIO.h:15,
from CommonIO.cc:11:
../HepMC/GenVertex.h:307:73: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
^
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:289:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:289:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:289:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenEvent.h:341:69: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:341:69: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:341:78: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
^
../HepMC/GenEvent.h:408:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:408:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:408:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
../HepMC/GenEvent.h:459:71: error: ‘ptrdiff_t’ was not declared in this scope
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^~~~~~~~~
../HepMC/GenEvent.h:459:71: note: suggested alternatives:
In file included from /usr/include/c++/7/string:38:0,
from CommonIO.cc:8:
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
typedef __PTRDIFF_TYPE__ ptrdiff_t;
^~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:232:28: note: ‘std::ptrdiff_t’
In file included from ../HepMC/CommonIO.h:15:0,
from CommonIO.cc:11:
../HepMC/GenEvent.h:459:80: error: template argument 3 is invalid
public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
^
CommonIO.cc: In member function ‘HepMC::HeavyIon* HepMC::CommonIO::read_heavy_ion(std::istream*)’:
CommonIO.cc:318:9: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:328:26: warning: converting ‘false’ to pointer type ‘HepMC::HeavyIon*’ [-Wconversion-null]
if( nh == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::PdfInfo* HepMC::CommonIO::read_pdf_info(std::istream*)’:
CommonIO.cc:344:9: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc:356:27: warning: converting ‘false’ to pointer type ‘HepMC::PdfInfo*’ [-Wconversion-null]
if( id1 == 0 ) return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenVertex* HepMC::CommonIO::read_vertex(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:374:9: warning: converting ‘false’ to pointer type ‘HepMC::GenVertex*’ [-Wconversion-null]
return false;
^~~~~
CommonIO.cc: In member function ‘HepMC::GenParticle* HepMC::CommonIO::read_particle(std::istream*, HepMC::TempParticleMap&)’:
CommonIO.cc:411:9: warning: converting ‘false’ to pointer type ‘HepMC::GenParticle*’ [-Wconversion-null]
return false;
^~~~~
Makefile:478: recipe for target 'CommonIO.lo' failed
make[1]: *** [CommonIO.lo] Error 1
make[1]: Leaving directory '/home/maxfieg/Desktop/FelixResearch/junk/hep_build2/HepMC2.04/src'
Makefile:397: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

Error with unique_ptr on Oculus project

I am currently working on a Oculus Rift project (DK1) on Ubuntu 14.04 and I try to compile a github projet.
This is a Qt project written in C++. I have the following error about "unique_ptr". I think have installed the right libraries. I know this code have already worked on a Ubuntu computer.
g++ -c -m64 -pipe -Ofast -Wno-deprecated -O2 -std=c++0x -Wall -W -fPIE -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -o Camera.o Camera.cpp
In file included from Include/OVR/LibOVR/Include/../Src/OVR_Device.h:33:0,
from Include/OVR/LibOVR/Include/OVR.h:35,
from Oculus.h:13,
from Input.h:13,
from Camera.h:12,
from Camera.cpp:1:
Include/OVR/LibOVR/Include/../Src/OVR_DeviceMessages.h: In constructor ‘OVR::MessageCameraFrame::MessageCameraFrame(OVR::DeviceBase*)’:
Include/OVR/LibOVR/Include/../Src/OVR_DeviceMessages.h:255:13: warning: ‘OVR::MessageCameraFrame::CameraHandle’ will be initialized after [-Wreorder]
UInt32* CameraHandle; // Identifies the camera object associated with this frame
^
Include/OVR/LibOVR/Include/../Src/OVR_DeviceMessages.h:249:18: warning: ‘const UByte* OVR::MessageCameraFrame::pFrameData’ [-Wreorder]
const UByte* pFrameData; // a ptr to frame data.
^
Include/OVR/LibOVR/Include/../Src/OVR_DeviceMessages.h:226:5: warning: when initialized here [-Wreorder]
MessageCameraFrame(DeviceBase* dev)
^
Camera.cpp: In constructor ‘Camera::Camera(const vec3&, const vec3&, const vec3&, float, float, const Input&)’:
Camera.cpp:20:18: error: use of deleted function ‘Input::Input(const Input&)’
speed_ {speed}
^
In file included from Camera.h:12:0,
from Camera.cpp:1:
Input.h:33:7: note: ‘Input::Input(const Input&)’ is implicitly deleted because the default definition would be ill-formed:
class Input
^
Input.h:33:7: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = GenericOculus; _Dp = std::default_delete<GenericOculus>]’
In file included from /usr/include/c++/4.8/memory:81:0,
from LogCpp/Log.h:8,
from Oculus.h:23,
from Input.h:13,
from Camera.h:12,
from Camera.cpp:1:
/usr/include/c++/4.8/bits/unique_ptr.h:273:7: error: declared here
unique_ptr(const unique_ptr&) = delete;
^
Camera.cpp:20:18: warning: a temporary bound to ‘Camera::input_’ only persists until the constructor exits [-Wextra]
speed_ {speed}
^
make: *** [Camera.o] Erreur 1
Thank you
The problem here lies in this message:
Input.h:33:7: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&)
You're apparently trying to construct a unique_ptr from another unique_ptr. That's forbidden, as unique_ptr can't be copied (that's the point of having a unique pointer). You can only move a unique_ptr to transfer ownership.
So you'll have to revise that code with this information in mind.
Note: As you apparently have a member unique_ptr in your class, and as its copy constructor is deleted (i.e. explicitely forbidden), thus the default copy constructor of your class is itself deleted, which explains the following error message in your stack:
Camera.cpp:20:18: error: use of deleted function ‘Input::Input(const Input&)

Objective-C++ ARC and C++ containers

I'm trying to compile my legacy-free libFoundation project, located at https://github.com/chmeeedalf/lf-foundation but running into problems using clang 3.4 and libc++. It appears something is not happy with ARC in the containers, and I see the following error excerpt:
In file included from /home/chmeee/git-lffoundation/src/Collections/NSCoreArray.mm:34:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSArray.h:31:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSObject.h:40:
In file included from /home/chmeee/git-lffoundation/src/../Headers/Foundation/NSRange.h:192:
In file included from /usr/include/c++/v1/algorithm:627:
/usr/include/c++/v1/memory:913:17: error: call to 'addressof' is ambiguous
{return _VSTD::addressof(__r);}
^~~~~~~~~~~~~~~~
/usr/include/c++/v1/__config:341:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/usr/include/c++/v1/vector:1678:65: note: in instantiation of member function 'std::__1::pointer_traits<const __strong id *>::pointer_to' requested here
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
^
/home/chmeee/git-lffoundation/src/Collections/NSCoreArray.mm:115:8: note: in instantiation of member function 'std::__1::vector<id, std::__1::allocator<id> >::insert' requested here
items.insert(items.begin() + index, anObject);
^
/usr/include/c++/v1/__functional_base:96:1: note: candidate function [with _Tp = const id]
addressof(__strong _Tp& __x) _NOEXCEPT
^
/usr/include/c++/v1/__functional_base:122:1: note: candidate function [with _Tp = const id]
addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
^
/usr/include/c++/v1/__functional_base:83:1: note: candidate function [with _Tp = const id]
addressof(_Tp& __x) _NOEXCEPT
^
1 error generated.
*** Error code 1
Stop.
make: stopped in /home/chmeee/git-lffoundation/src
Exit 1
The file in this example has a std::vector declared as:
std::vector<id> items;
Can someone shed some light onto this problem? I tried adding an explicit __strong in the std::vector declaration, to no avail, however __unsafe_unretained does eliminate the error.
I'm building on FreeBSD -CURRENT, using the libc++ and clang 3.4 that is in base.
Answering my own question, in case others are interested. Clang defines __weak as a preprocessor macro for ARC. However, FreeBSD's <sys/cdefs.h> also defines __weak itself. The workaround I found for this was to add to my local <sys/cdefs.h>:
#ifndef __weak
#define __weak what_freebsd_defines_ass
#endif

Building C++ application with pre-build library gives compile errors

I am trying to modify a C++ program by including POCO to be able to do a HTTP request and receive a result. Basically, I just need within another C++ program to give a username and password and get a plain "OK" or "ERROR" response.
I am not familiar with C++ at all (use Java mainly). I build the POCO project and installed it without any problems, but when I add it to the project I get a while pile of compiler errors when building:
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
In file included from /usr/local/include/Poco/Timespan.h:44:
/usr/local/include/Poco/Timestamp.h:50:1: error: declaration of anonymous class must be a definition
class Foundation_API Timestamp
^
/usr/local/include/Poco/Timestamp.h:149:24: error: expected identifier
inline bool Timestamp::operator == (const Timestamp& ts) const
^
/usr/local/include/Poco/Timestamp.h:149:13: error: declaration of anonymous struct must be a definition
inline bool Timestamp::operator == (const Timestamp& ts) const
^
../crtmpserver/sources/common/include/platform/osx/osxplatform.h:109:19: note: expanded from macro 'Timestamp'
#define Timestamp struct tm
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
In file included from /usr/local/include/Poco/Timespan.h:44:
/usr/local/include/Poco/Timestamp.h:262:1: error: expected unqualified-id
} // namespace Poco
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:44:
In file included from /usr/local/include/Poco/Net/StreamSocket.h:44:
In file included from /usr/local/include/Poco/Net/Socket.h:44:
In file included from /usr/local/include/Poco/Net/SocketImpl.h:47:
/usr/local/include/Poco/Timespan.h:54:21: error: no struct named 'TimeDiff' in 'tm'
typedef Timestamp::TimeDiff TimeDiff;
~~~~~~~~~~~^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
In file included from /usr/local/include/Poco/Net/HTTPClientSession.h:44:
In file included from /usr/local/include/Poco/Net/HTTPSession.h:47:
/usr/local/include/Poco/Any.h:123:46: error: cannot use typeid with -fno-rtti
return _content ? _content->type() : typeid(void);
^
/usr/local/include/Poco/Any.h:149:20: error: cannot use typeid with -fno-rtti
return typeid(ValueType);
^
/usr/local/include/Poco/Any.h:180:42: error: cannot use typeid with -fno-rtti
return operand && operand->type() == typeid(ValueType)
^
In file included from ../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:30:
/usr/local/include/Poco/Net/HTTPClientSession.h:291:8: error: expected member name or ';' after declaration specifiers
Poco::Timestamp _lastRequest;
~~~~ ^
../crtmpserver/sources/common/include/platform/osx/osxplatform.h:109:19: note: expanded from macro 'Timestamp'
#define Timestamp struct tm
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:94:10: error: expected expression
form.add(<D2>entry1<D3>, <D2>value1<D3>);
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:97:25: error: variable has incomplete type 'Poco::Net::HTTPResponse'
Poco::Net::HTTPResponse response;
^
/usr/local/include/Poco/Net/HTTPClientSession.h:55:7: note: forward declaration of 'Poco::Net::HTTPResponse'
class HTTPResponse;
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:99:41: error: no member named 'cout' in namespace 'std'; did you mean 'count'?
Poco::StreamCopier::copyStream(rs, std::cout);
~~~~~^~~~
count
/usr/include/c++/4.2.1/bits/stl_algo.h:424:5: note: 'count' declared here
count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
^
../crtmpserver/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp:99:36: error: address of overloaded function 'count' does not match required type 'std::basic_ostream<char>'
Poco::StreamCopier::copyStream(rs, std::cout);
^~~~~~~~~
/usr/include/c++/4.2.1/bits/stl_algo.h:424:5: note: candidate function
count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
^
/usr/local/include/Poco/StreamCopier.h:57:73: note: passing argument to parameter 'ostr' here
static std::streamsize copyStream(std::istream& istr, std::ostream& ostr, std::size_t bufferSize = 8192);
^
13 errors generated.
make[2]: *** [applications/idomsconnector/CMakeFiles/idomsconnector.dir/Users/[...]/sources/applications/idomsconnector/src/rtmpappprotocolhandler.cpp.o] Error 1
make[1]: *** [applications/idomsconnector/CMakeFiles/idomsconnector.dir/all] Error 2
make: *** [all] Error 2
build failed
My code fragment is as follows:
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/StreamCopier.h>
string RTMPAppProtocolHandler::GetAuthPassword(string user) {
INFO("Testing auth: %s", STR(user));
Poco::Net::HTTPClientSession s("www.somehost.com");
//s.setProxy("localhost", srv.port());
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/large");
Poco::Net::HTMLForm form;
form.add(“entry1”, “value1”);
form.prepareSubmit(request);
s.sendRequest(request);
Poco::Net::HTTPResponse response;
std::istream& rs = s.receiveResponse(response);
Poco::StreamCopier::copyStream(rs, std::cout);
return user;
}
Am I doing something stupid? It is only this little interaction with a HTTP server which I need to modify, so I am just looking for a very simple solution but find it hard to find something that works easy (mainly because I am not familiar with C++ though)

/boost/lockfree/queue.hpp: error: static assertion failed: (boost::has_trivial_destructor<T>::value)

I'm trying to substitute boost::lockfree::queue for std::queue in this file https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp
I've added #include <boost/lockfree/queue.hpp>; changed line 130, std::queue<action> m_actions;, to boost::lockfree::queue<action> m_actions;; removed all lines having to do with locking; and changed line 103, m_actions.pop();, to m_actions.pop(a);.
I get these errors when I scons broadcast_server_lockfree in the project root after adding broadcast_server_lockfree = SConscript('#/broadcast_server_lockfree/SConscript',variant_dir = builddir + 'broadcast_server_lockfree',duplicate = 0) to the project root's SConstruct and using broadcast_server's SConstruct in the broadcast_server_lockfree directory:
root#server:~/websocketpp-experimental# scons broadcast_server_lockfree
scons: Reading SConscript files ...
C++11 build environment partially enabled
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build/release/broadcast_server_lockfree
g++ -o build/release/broadcast_server_lockfree/broadcast_server_lockfree.o -c -std=c++0x -Wall -Wcast-align -isystem /root/boost_1_53_0 -DNDEBUG -D_WEBSOCKETPP_CPP11_MEMORY_ -D_WEBSOCKETPP_CPP11_FUNCTIONAL_ -D_WEBSOCKETPP_CPP11_SYSTEM_ERROR_ -D_WEBSOCKETPP_CPP11_RANDOM_DEVICE_ -D_WEBSOCKETPP_NOEXCEPT_ -I. broadcast_server_lockfree/broadcast_server_lockfree.cpp
In file included from broadcast_server_lockfree/broadcast_server_lockfree.cpp:10:0:
/root/boost_1_53_0/boost/lockfree/queue.hpp: In instantiation of 'class boost::lockfree::queue<action>':
broadcast_server_lockfree/broadcast_server_lockfree.cpp:139:36: required from here
/root/boost_1_53_0/boost/lockfree/queue.hpp:79:5: error: static assertion failed: (boost::has_trivial_destructor<T>::value)
/root/boost_1_53_0/boost/lockfree/queue.hpp:83:5: error: static assertion failed: (boost::has_trivial_assign<T>::value)
broadcast_server_lockfree/broadcast_server_lockfree.cpp: In member function 'void broadcast_server::process_messages()':
broadcast_server_lockfree/broadcast_server_lockfree.cpp:111:34: error: 'class boost::lockfree::queue<action>' has no member named 'front'
broadcast_server_lockfree/broadcast_server_lockfree.cpp:117:55: error: 'm_connection_lock' was not declared in this scope
broadcast_server_lockfree/broadcast_server_lockfree.cpp:120:55: error: 'm_connection_lock' was not declared in this scope
broadcast_server_lockfree/broadcast_server_lockfree.cpp:123:55: error: 'm_connection_lock' was not declared in this scope
In file included from broadcast_server_lockfree/broadcast_server_lockfree.cpp:10:0:
/root/boost_1_53_0/boost/lockfree/queue.hpp: In instantiation of 'boost::lockfree::queue<T, A0, A1, A2>::~queue() [with T = action; A0 = boost::parameter::void_; A1 = boost::parameter::void_; A2 = boost::parameter::void_]':
broadcast_server_lockfree/broadcast_server_lockfree.cpp:41:24: required from here
/root/boost_1_53_0/boost/lockfree/queue.hpp:229:11: error: no matching function for call to 'action::action()'
/root/boost_1_53_0/boost/lockfree/queue.hpp:229:11: note: candidates are:
broadcast_server_lockfree/broadcast_server_lockfree.cpp:32:5: note: action::action(action_type, websocketpp::endpoint<websocketpp::connection<websocketpp::config::asio>, websocketpp::config::asio>::message_ptr)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:32:5: note: candidate expects 2 arguments, 0 provided
broadcast_server_lockfree/broadcast_server_lockfree.cpp:31:5: note: action::action(action_type, websocketpp::connection_hdl)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:31:5: note: candidate expects 2 arguments, 0 provided
broadcast_server_lockfree/broadcast_server_lockfree.cpp:30:8: note: action::action(const action&)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:30:8: note: candidate expects 1 argument, 0 provided
In file included from broadcast_server_lockfree/broadcast_server_lockfree.cpp:10:0:
/root/boost_1_53_0/boost/lockfree/queue.hpp: In instantiation of 'boost::lockfree::queue<T, A0, A1, A2>::node::node(boost::lockfree::queue<T, A0, A1, A2>::node::handle_type) [with T = action; A0 = boost::parameter::void_; A1 = boost::parameter::void_; A2 = boost::parameter::void_; boost::lockfree::queue<T, A0, A1, A2>::node::handle_type = boost::lockfree::queue<action>::node*]':
/root/boost_1_53_0/boost/lockfree/detail/freelist.hpp:82:13: required from 'T* boost::lockfree::detail::freelist_stack<T, Alloc>::construct(const ArgumentType&) [with bool ThreadSafe = true; bool Bounded = false; ArgumentType = boost::lockfree::queue<action>::node*; T = boost::lockfree::queue<action>::node; Alloc = std::allocator<boost::lockfree::queue<action>::node>]'
/root/boost_1_53_0/boost/lockfree/queue.hpp:126:75: required from 'void boost::lockfree::queue<T, A0, A1, A2>::initialize() [with T = action; A0 = boost::parameter::void_; A1 = boost::parameter::void_; A2 = boost::parameter::void_]'
/root/boost_1_53_0/boost/lockfree/queue.hpp:166:9: required from 'boost::lockfree::queue<T, A0, A1, A2>::queue() [with T = action; A0 = boost::parameter::void_; A1 = boost::parameter::void_; A2 = boost::parameter::void_]'
broadcast_server_lockfree/broadcast_server_lockfree.cpp:41:24: required from here
/root/boost_1_53_0/boost/lockfree/queue.hpp:109:52: error: no matching function for call to 'action::action()'
/root/boost_1_53_0/boost/lockfree/queue.hpp:109:52: note: candidates are:
broadcast_server_lockfree/broadcast_server_lockfree.cpp:32:5: note: action::action(action_type, websocketpp::endpoint<websocketpp::connection<websocketpp::config::asio>, websocketpp::config::asio>::message_ptr)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:32:5: note: candidate expects 2 arguments, 0 provided
broadcast_server_lockfree/broadcast_server_lockfree.cpp:31:5: note: action::action(action_type, websocketpp::connection_hdl)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:31:5: note: candidate expects 2 arguments, 0 provided
broadcast_server_lockfree/broadcast_server_lockfree.cpp:30:8: note: action::action(const action&)
broadcast_server_lockfree/broadcast_server_lockfree.cpp:30:8: note: candidate expects 1 argument, 0 provided
scons: *** [build/release/broadcast_server_lockfree/broadcast_server_lockfree.o] Error 1
scons: building terminated because of errors.
I know next to nothing about c++, and searches on the error have yielded nothing (since I have no idea what I'm reading).
Here's the boost::lockfree::queue example if it helps. http://boost-sandbox.sourceforge.net/doc/html/lockfree/examples.html
Please show me how to correct this.
action
struct action {
action(action_type t, connection_hdl h) : type(t), hdl(h) {}
action(action_type t, server::message_ptr m) : type(t), msg(m) {}
action_type type;
websocketpp::connection_hdl hdl;
server::message_ptr msg;
};
From the docs:
T must have a copy constructor, a trivial assignment operator, and a trivial destructor.
Thus your action class must look like the following:
class action
{
public:
action(const action& rhs) { ... }
//Implicitly defined destructor for itself and all member variables
//Implicitly defined operator= for itself and all member variables
};
The static_asserts are complaining because your destructor and operator= are not implicitly defined by the compiler (or this is the case for at least one member variable of action).
Edit: I've had a quick look at the repo - I can't seem to find connection_hdl, and there is no message_ptr in template <typename endpoint> class server. Either way, one of websocketpp::connection_hdl hdl or server::message_ptr msg does not satisfy the above conditions. Just "dropping in" a lockfree queue instead of using a std::queue is likely a non-trivial task which will require a number of changes.
This question has been answer well by the above posting. Here I will provide more examples. The fruitful discussion gave a lots of guidance please read them. The real matter is the requirement for the template type of the queue. For practicality, let's look at some real use cases.
namespace lkf=boost::lockfree;
vector<lkf::spsc_queue<pair<Fastq*,int>, lkf::capacity<100>>> datastore;
//lkf::queue<pair<char*,char*>, lkf::capacity<100>> pile1, pile2; //failed assert
lkf::queue<pair<char*,char*>*, lkf::capacity<100>> pile1, pile2;
The first line in the code passed the compiler (because it is spac_queue), but the second line pair failed the compiler (due to boost::ASSERT):
/usr/local/include/boost/lockfree/queue.hpp:99:5: error: static assertion failed: (boost::has_trivial_assign<T>::value)
BOOST_STATIC_ASSERT((boost::has_trivial_assign<T>::value));
After converting pair to pointer type (line 3), the compiler is happy.
Could be boost assertion needs to be updated? Converting to pointer is one quick trick, may not be the best.
The boost lockfree::queue has three Requirements:
T must have a copy constructor
T must have a trivial assignment operator
T must have a trivial destructor
spsc_queue has two:
T must have a default constructor
T must be copyable
I got this error when I used std::string for the queue item type.
boost::lockfree::queue<string>(10000)
As many good people have pointed out in the answers here and here, string is not allowed to be used for boost::lockfree::queue.
It does compiled with char *
boost::lockfree::queue<char*>(10000)