这个C++代码段做了什么?
问题描述:
有人能告诉我这段代码干什么吗?这个C++代码段做了什么?
const boost::system::error_code&
我怀疑这个代码是用来连接功能,通过指针, 但它的一切它做什么?
有全码:
#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
void print(const boost::system::error_code&)
{
std::cout<<"hello word\n";
}
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.async_wait(&print);
io.run();
return 0;
}
答
我不知道boost::asio
,但我怀疑boost::asio::deadline_timer::async_wait()
需要一个函数取类型const boost::system::error_code&
的一个参数。为了呼叫async_wait()
,你必须传递一个指向这样一个函数的指针。
void print(const boost::system::error_code&)
就是这样一个功能。
如果您不想使用函数参数,则可以不指定它。这样可以防止在未使用提供的函数参数之一时编译器通常发出警告。
你能展示更多的代码,上下文,你的问题的原因? –
它指定了一个类型,但没有声明的其余部分它什么都不做。 –
这可能有所帮助:http://stackoverflow.com/questions/2490456/how-to-use-unnamed-function-arguments-in-c-or-c – Nim