http://www.mitbbs.com//article_t/Programming/31465203.html
发信人: bihai (学得不好), 信区: Programming
标 题: 我是否需要Move(C++11)?
发信站: BBS 未名空间站 (Mon Dec 28 12:57:37 2015, 美东)
有一个类,TCPServer{
public: TCPServer(asio::io_service& io_service, const tcp::endpoint& listen_
endpoint){...}
private:
asio::io_service& io_service_;
asio::ip::tcp::acceptor acceptor_;
TCPListener listener_;
};
这个类是boost的一个例子。我的代码需要三个变量,放在TCPServerManager里面,为
简单起见,我定义三个static变量。
TCPServerManager{
static TCPServer eth0, eth1, wifi;
static void start(){...}
};
那么,在start里面,我根据boost的例子,用TCPServer s(io_service, listen_
endpoint);定义了一个变量。怎么把这个变量变成我的eth0,eth1, wifi呢?
在定义eth0的那个地方,需要的listen_endpoint还没有好,就是说,需要后续的代码
(start)来完成listen_endpoint的赋值。
我是否需要eth0=std::move(s); 那样,我自己写TCPServer的move assignment怎么写
呢?虽然一共三个变量,还是需要请教懂行的。
另外,我是否可以使用TCPServer *eth0=new TCPServer(.) 这样可以在start函数里
面执行。算是另外一种方法吧。
--
评论
发表评论