关于BOOST引用问题

Flaght 2009-11-09 01:28:40

#include "stdafx.h"
#include <stdio.h>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include<boost/date_time/posix_time/posix_time.hpp>
using namespace boost;
void print(const asio::error&/*e*/,asio::deadline_timer *t,int* count)
{
if (*count <5)
{
std::cout<<*count<<"\n";
++(*count);

t->expires_at(t->expires_at()+boost::posix_time::seconds(1));
t->async_wait(boost::bind(print,asio::placeholders::error,t,count));
}
}
int _tmain(int argc, _TCHAR* argv[])
{
asio::io_service io;
int count =0;
asio::deadline_timer t(io,boost::posix_time::seconds(1));
t.async_wait(boost::bind(print,asio::placeholders::error,&t,&count));

io.run();

std::cout<<"Final count is"<<count<<"\n";

return 0;
}


会出现下面的错:
1>e:\test\vs2008\anytest\anytest\anytest.cpp(10) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\test\vs2008\anytest\anytest\anytest.cpp(10) : error C2751: “boost::asio::error”: 无法限定函数参数的名称
1>e:\test\vs2008\anytest\anytest\anytest.cpp(10) : error C2143: 语法错误 : 缺少“,”(在“&”的前面)
1>e:\test\vs2008\anytest\anytest\anytest.cpp(12) : error C2065: “count”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(14) : error C2065: “count”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(15) : error C2065: “count”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(17) : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(17) : error C2227: “->expires_at”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>e:\test\vs2008\anytest\anytest\anytest.cpp(17) : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(17) : error C2227: “->expires_at”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>e:\test\vs2008\anytest\anytest\anytest.cpp(18) : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(18) : error C2227: “->async_wait”的左边必须指向类/结构/联合/泛型类型
1> 类型是“'unknown-type'”
1>e:\test\vs2008\anytest\anytest\anytest.cpp(18) : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(18) : error C2065: “count”: 未声明的标识符
1>f:\project\daoim\sdk\boost_1_36_0\boost\bind.hpp(67) : error C2825: 'F': 当后面跟“::”时必须为类或命名空间
1> f:\project\daoim\sdk\boost_1_36_0\boost\bind\bind_template.hpp(15): 参见对正在编译的类 模板 实例化“boost::_bi::result_traits<R,F>”的引用
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=void (__cdecl *)(int)
1> ]
1> e:\test\vs2008\anytest\anytest\anytest.cpp(26): 参见对正在编译的类 模板 实例化“boost::_bi::bind_t<R,F,L>”的引用
1> with
1> [
1> R=boost::_bi::unspecified,
1> F=void (__cdecl *)(int),
1> L=boost::_bi::list3<boost::arg<1>,boost::_bi::value<boost::asio::basic_deadline_timer<boost::posix_time::ptime> *>,boost::_bi::value<int *>>
1> ]
1>f:\project\daoim\sdk\boost_1_36_0\boost\bind.hpp(67) : error C2039: “result_type”: 不是“`global namespace'”的成员
1>f:\project\daoim\sdk\boost_1_36_0\boost\bind.hpp(67) : error C2146: 语法错误 : 缺少“;”(在标识符“type”的前面)
1>f:\project\daoim\sdk\boost_1_36_0\boost\bind.hpp(67) : error C2208: “boost::_bi::type”: 没有使用此类型进行定义的成员
1>f:\project\daoim\sdk\boost_1_36_0\boost\bind.hpp(67) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译

请问这是怎么回事啊?
...全文
508 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackyjkchen 2009-11-09
  • 打赏
  • 举报
回复
error只是个asio下的命名空间吧,等于说你的类型没有,参数名也没有
jackyjkchen 2009-11-09
  • 打赏
  • 举报
回复
const asio::error&这个地方怎么回事?参数名呢?

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧