I'm writing a wrapper for Boost Socket. We have a class that uses the Boost socket, but we need to wrap it so we can mock it so we can fake calls back from it for unit testing. This is not about that.
I wrote the wrapper, creatively called BoostSocketWrapper
, and created endpoints for the socket endpoints we use. The wrapper holds the instance of the real socket, and just passes the calls onto the real socket. But because all the functions are virtual, we can override them and mock them with Google Mock.
I got all the endpoints in place, but as soon as I had the last one written, I got a new error. g++ claims it can't find the constructor for the wrapper. It doesn't complain about it if I remove one of the necessary endpoints, and I can only assume that's because it detects other errors and doesn't even try to construct it yet.
Since this is C++11, we're using a unique pointer for the class. There's nothing really special about the call to create it:
theSocket = make_unique<BoostSocketWrapper>(ioService);
We defined our own version of make_unique()
for reasons that aren't entirely clear, but I know make_unique()
wasn't defined in C++ until C++14. It's used in hundreds of other places in the code:
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
ioService
is a passed-in value, and it worked perfectly for the raw Boost socket when that was in-place. It's defined as a boost::asio::io_service
. The constructor endpoint in the wrapper is identical to the Boost one:
class BoostSocketWrapper {
public:
/**
* @brief Constructor that creates the Boost Socket
*
* @param ioService
*/
BoostSocketWrapper(boost::asio::io_service& ioService);
virtual ~BoostSocketWrapper() {}
...
}
But g++ it claims it can't find it:
undefined reference to `speca::BoostSocketWrapper::BoostSocketWrapper(boost::asio::io_context&)'
I've tried it using just std::unique_ptr as well, but that spews a similar error:
error: no matching function for call to ‘std::unique_ptr<speca::BoostSocketWrapper>::unique_ptr(boost::asio::io_service&)’
I've banged my head against this all day, but it hasn't helped. None of the other C++ coders here understand it either. Here is the gist of the BoostSocketWrapper
declaration, and the header is included in the files where I try to allocate it:
#pragma once
#include <boost/asio.hpp>
namespace sprocketa {
class BoostSocketWrapper {
public:
BoostSocketWrapper(boost::asio::io_service& ioService);
virtual ~BoostSocketWrapper() {}
virtual void open( const boost::asio::ip::basic_endpoint<boost::asio::ip::udp>::protocol_type & protocol );
...
private:
// this constructs fine in the implementation
std::unique_ptr<boost::asio::ip::udp::socket> theSocket = nullptr;
}
} // namespace sprocketa
The class we're trying allocate it from is in the same namespace. We're using C++11 with g++ and Eclipse CDT as the IDE.
What am I missing here?
Aucun commentaire:
Enregistrer un commentaire