首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Visual Studio2010中使用tr1 (tr1::function)?

如何在Visual Studio2010中使用tr1 (tr1::function)?
EN

Stack Overflow用户
提问于 2012-05-02 03:14:04
回答 2查看 4.7K关注 0票数 8

如何开始使用Visual Studio2010的tr1特性?对于更具体的情况,我需要std::tr1::函数。我尝试包含报告为丢失的#include <tr1/functional>,而#include <functional>包含正常,但当我设置以下内容时:

代码语言:javascript
复制
std::tr1::function<void(void)> callback;

我得到了:

代码语言:javascript
复制
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仍然会返回相同的结果:

代码语言:javascript
复制
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 ';'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-02 03:57:07

基于你的评论和this page,我认为Marmalade附带了它自己的STL实现,这似乎已经过时了。This page验证他们使用的STLPort版本不支持2005年发布的TR1,更不用说更新的版本了。您可以选择:

1)自己复制/编写

2)没有

3) Download a newer version of STLPort。它似乎在过去两年中没有更新过,所以没有C++11,但他们确实提到了functional,但不清楚它是在std还是std::tr1名称空间中。但是,这可能不适用于Marmalade,因此请进行备份并小心。

票数 8
EN

Stack Overflow用户

发布于 2012-05-02 03:18:49

Visual Studio2010附带了默认启用的C++11 (或者至少是实现的)。您需要使用std::function<void(void)>

以获取完整的表see here

顺便说一句:你现在不应该使用TR1的任何东西。它已被集成到新标准中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10402924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档