【发布时间】:2012-05-11 06:55:20
【问题描述】:
如何开始使用 Visual Studio 2010 的 tr1 功能?对于更具体的情况,我需要 std::tr1::function。我尝试包含报告为丢失的#include <tr1/functional>,而#include <functional> 包含很好,但是当我设置这个时:
std::tr1::function<void(void)> callback;
我明白了:
1>d:\marmalade\projects\core\src\button.h(21): error C3083: 'tr1': the symbol to the left of a '::' must be a type
1>d:\marmalade\projects\core\src\button.h(21): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(21): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(21): error C2238: unexpected token(s) preceding ';'
如果我使用 boost,它可以正常工作,但是对于这个项目,由于使用了特定的框架,我需要 Visual Studio tr1 版本。
按照建议,跳过 tr1,仍然返回相同的结果:
std::function<void(void)> callback;
1>d:\marmalade\projects\core\src\button.h(20): error C2039: 'function' : is not a member of '_STL'
1>d:\marmalade\projects\core\src\button.h(20): error C2143: syntax error : missing ';' before '<'
1>d:\marmalade\projects\core\src\button.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\marmalade\projects\core\src\button.h(20): error C2238: unexpected token(s) preceding ';'
【问题讨论】:
-
tr1代表Technical Report 1,它是对 C++ 标准的提议添加的列表。一旦提案被接受,tr1名称就过时了。 -
你
include <functional>了吗? -
错误表明功能不是_STL的成员。你确定你写的是
std::function,而不是std::functional? -
复制了错误的错误。我尝试了两个版本,结果都一样。
-
@Speed 如果你把那个宏放进去并且得到一个你正在重新定义
std的错误,这意味着某人,在某个地方已经做了#define std。把#undef std放在你的include后面,然后找到并射杀将std定义为宏的人。
标签: c++ visual-studio-2010 c++11 std tr1