Question

My compiler errors are extremely long because g++ tells me the many 'candidates' for the functions that I am using wrong. What can I do?

server.cpp:78:51: note: candidates are:
/usr/include/boost/asio/buffer.hpp:599:26: note: boost::asio::mutable_buffers_1  boost::asio::buffer(const boost::asio::mutable_buffer&)
/usr/include/boost/asio/buffer.hpp:599:26: note:   candidate expects 1 argument, 2 provided
... 30 lines of error for one wrong line of code
Était-ce utile?

La solution

C++ is a fine, heavyweight programming language, but no one has ever figured out how to get it to issue readable error messages. I am afraid that the error messages you mention are complicated because, as seen from the compiler's perspective, the error is complicated. If you take the time to read the message carefully, and think about it a while, you may begin to understand why this must be so.

Let's break your error message down:

server.cpp:78:51: note: candidates are:

This means that the error seems to originate on line 78 (or is it line 51?) of server.cpp. However, the reason the compiler believes that it is an error is found in a Boost header, asio/buffer.hpp. It is probably fruitless to examine that header, since the header is probably both compicated and correct. Nevertheless, the next line of the error message extracts from the Boost header the information you need:

note: boost::asio::mutable_buffers_1  boost::asio::buffer(const boost::asio::mutable_buffer&)

So, back on line 78 of server.cpp, you have called boost::asio::buffer(), right? As an argument between parentheses, that function wants an object of type boost::asio::mutable_buffer. Did you give it one? If yes, are you sure? Evidently, for some reason, the compiler does not recognize your argument as having the correct type.

Now let's look at the third line of the error:

note:   candidate expects 1 argument, 2 provided

So, actually, back on line 78 of server.cpp, you have given not one but two arguments to boost::asio::buffer(). That is, you have called boost::asio::buffer(x, y) rather than boost::asio::buffer(x) -- or, if you haven't, the compiler thinks that you have.

Trace these steps. They should solve your problem.

For information, I fairly often get C++ error messages that fill half my screen or more. I don't like them any more than you do, but I do understand why the compiler issues them. C++'s powerful template facility in particular makes for some pretty hefty error messages when library features are misused. It's the nature of the language. One can do little but reconcile oneself to this nature, if one will program in C++.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top