8
拿下面一段使用boost :: asio的代码。奇怪的C4512警告。为什么?
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
class SocketTest
{
private:
boost::asio::io_service& mIOService;
tcp::acceptor mAcceptor; // Comment this line
public:
SocketTest(boost::asio::io_service& io_service)
: mIOService(io_service)
, mAcceptor(io_service, tcp::endpoint(tcp::v4(), 8080)) // Comment this line
{
}
};
如果你对此有何评论这两个标记的系编译器(Visual Studio 2010中)给出了对编译/ W4时,下面的警告。
warning C4512: 'SocketTest' : assignment operator could not be generated
是什么让这两条线如此特别?为什么他们的存在允许生成赋值运算符?
啊,是的。你似乎是对的。继承boost :: noncopyable解决了警告。这也解释了为什么我尝试用原子类型(int&和int)重新创建问题不会重新创建问题。非常感谢。 – UberMongoose
从未来更新:在C++ 11中有更好的方法来处理这个问题:http://stackoverflow.com/questions/9458741/with-explicitly-deleted-member-functions-in-c11-is-it-still -worthwhile到INH – Tim