views:

126

answers:

1

With desperate battle with Boost.Asio, i met a lot of difficulties.

One of them is that i can hardly locate where the "boost::noncopyable errors" are!!

If i violate the noncopyable regulation accidently, IDE only shows me some errors in noncopyable.hpp or somewhere else but nowhere in my files.

I can only find errors by comment&uncomment everywhere asio object exist.

(ps: my IDE is visual c++ 2008, is this IDE has bad relationship with Boost??)

EDIT:

I know that reading the whole error message helps alot. But how 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>  ]

It's all caused by this

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

(it should be:

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

)

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

(ps2: perhaps all these troubles are caused by my pooooooor c++ programming experience??)

+1  A: 

It seems VC++ simply won't tell you where the attempt to use the copy constructor is.

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

On a few occasions I have just managed to compile the source with GCC to figure out VC++'s error messages (and the other way around).

Perhaps also don't write much non-working code without trying to compile it occasionally.

UncleBens
It's not clear to me that the compiler is not telling OP where the reference to copy constructor happens. He notes himself that he found the line of code - "it's all caused by this" - and it seems likely to me that's the header file line referenced at the top of the error message.
Steve Townsend
I don't think `boost` itself is buggy. There are three things: 1) error (boost::noncopyable is not copyable), 2) what caused the error (automatically generating the copy-constructor for a noncopyable class, 3) which line in user's code requires the copy constructor. The message does not contain the 3rd item. I assume OP found the culprit by studying the code very hard. VC++ does not point to the actual place where the copy constructor is invoked.
UncleBens