免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4700 | 回复: 0
打印 上一主题 下一主题

[C++] 关于BOOST引用问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-09 11:52 |只看该作者 |倒序浏览
#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)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (*count <5)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::cout<<*count<<"\n";
&nbsp;&nbsp;&nbsp;&nbsp;    ++(*count);

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

&nbsp;&nbsp;&nbsp;&nbsp;io.run();

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

&nbsp;&nbsp;&nbsp;&nbsp;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(1 : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(1 : error C2227: “->async_wait”的左边必须指向类/结构/联合/泛型类型
1>        类型是“'unknown-type'”
1>e:\test\vs2008\anytest\anytest\anytest.cpp(1 : error C2065: “t”: 未声明的标识符
1>e:\test\vs2008\anytest\anytest\anytest.cpp(1 : 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: 无法从以前的错误中恢复;正在停止编译

请问这是为什么啊? 是我引用命名空间的问题吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP