Boost库菜鸟问题

Hue 2004-11-27 12:26:22
为什么在VC6中这段代码不能编译通过呢?
#include "stdafx.h"
#include <boost/lexical_cast.hpp>

int main()
{
using boost::lexical_cast;
int iTest = lexical_cast<int>("100");
int iTest2 = lexical_cast<int>("0");
return 0;
}
错误信息:
Compiling...
BoostTest.cpp
E:\Code\TestSrc\BoostTest\BoostTest.cpp(11) : error C2062: type 'int' unexpected
E:\Code\TestSrc\BoostTest\BoostTest.cpp(12) : error C2062: type 'int' unexpected
...全文
116 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jinhao 2004-11-27
  • 打赏
  • 举报
回复
读namespace中的模板函数提供显式的参数模板就会出现这个情况

namespace test
{
template<typename T>
void fun(){}
}

int main()
{
using test::fun; //using direcetive
fun<int>(); //显示提供了模板参数,而且上面使用的是using directive,编译不过
return 0;
}

应该换成
using namespace test //using declaration
int main()
{
fun<int>(); //OK, 或不使用using declaration,test::fun<int>(); 也OK
return 0;
}
njSeeWhy 2004-11-27
  • 打赏
  • 举报
回复
回复人: Jinhao(辣子鸡丁)(短歌马甲 No.0::Rome Total War这游戏好玩) ( ) 信誉:90

VC6的BUG,这个BUG导致这里不能使用using directive,而换成using declaration

我在vc6下试了,可以用using directive呀——至少对于std命名空间是可以的。
orangeczh 2004-11-27
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include <boost/lexical_cast.hpp>
using namespace boost;

int main()
{
//using boost::lexical_cast;
int iTest = lexical_cast<int>("100");
int iTest2 = lexical_cast<int>("0");
return 0;
}
Jinhao 2004-11-27
  • 打赏
  • 举报
回复
VC6的BUG,这个BUG导致这里不能使用using directive,而换成using declaration
#include "stdafx.h"
#include <boost/lexical_cast.hpp>

int main()
{
int iTest = boost::lexical_cast<int>("100");
int iTest2 = boost::lexical_cast<int>("0");
return 0;
}

或者
using namespace boost;
int main()
{
int iTest = lexical_cast<int>("100");
int iTest2 = lexical_cast<int>("0");
return 0;
}
njSeeWhy 2004-11-27
  • 打赏
  • 举报
回复
去掉#include "stdafx.h"这句试试。
somedummy 2004-11-27
  • 打赏
  • 举报
回复
问题还是应该起源于VC++6对template的支持有很大的问题……

24,856

社区成员

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

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