How to find "boost :: notcopyable" errors?

In a desperate battle with Boost.Asio, I met many difficulties.

One of them is that I can hardly find where the "boost :: notcopyable errors" are !!

If I mistakenly violate the unavailability procedure, the IDE shows only some errors in noncopyable.hpp or elsewhere, but nowhere in my files .

I can only find errors with comments and uncomment wherever an asio object exists.

(ps: my IDE is a visual C ++ 2008, does this IDE have a bad relationship with Boost?)

EDIT:

I know that reading the error message whole helps. But what about this?

1>d:\boost\include\boost-1_42\boost\asio\basic_io_object.hpp(92) : error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable' 1> d:\boost\include\boost-1_42\boost\noncopyable.hpp(27) : see declaration of 'boost::noncopyable_::noncopyable::noncopyable' 1> d:\boost\include\boost-1_42\boost\noncopyable.hpp(22) : see declaration of 'boost::noncopyable_::noncopyable' 1> This diagnostic occurred in the compiler generated function 'boost::asio::basic_io_object<IoObjectService>::basic_io_object(const boost::asio::basic_io_object<IoObjectService> &)' 1> with 1> [ IoObjectService=boost::asio::stream_socket_service<boost::asio::ip::tcp> ] 

All this is caused by this.

 tcp::socket getSocket(){ return m_socket; } 

(it should be:

 tcp::socket& getSocket(){ return m_socket; } 

)

When there are many functions in this file, can you guys quickly find it?

(ps2: maybe all of these problems are caused by my experience with pooooooor c ++ programming?)

+4
source share
2 answers

It seems that VC ++ just won't tell you where to try using the copy constructor.

For example, g ++ does:

 #include <boost/asio.hpp> using boost::asio::ip::tcp; class X { tcp::socket s; public: tcp::socket get() { return s; } }; 

Results in:

 blah blah blah noncopyable blah blah ... untitled1.cpp: In member function 'boost::asio::blah blah X::get()': untitled1.cpp:8: note: synthesized method 'boost::asio::blah(const boost::asio::blah&)' first required here 

In some cases, I just managed to compile the source with GCC to figure out the VC ++ error messages (and vice versa).

Perhaps also do not write a lot of non-working code without trying to compile it occasionally.

+3
source

I recently ran into a similar problem when an item that could not be copied was a member of a class that I would like to return by reference.

I followed this up by making copy constructors private for a couple of suspicious classes and found the problem this way.

Not very useful if you are returning an instance of an accelerator class without copying.

+1
source

All Articles