【问题标题】:How to use tr1 with Visual Studio 2010 (tr1::function)?如何在 Visual Studio 2010 (tr1::function) 中使用 tr1?
【发布时间】: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 &lt;functional&gt;了吗?
  • 错误表明功能不是_STL的成员。你确定你写的是std::function,而不是std::functional
  • 复制了错误的错误。我尝试了两个版本,结果都一样。
  • @Speed 如果你把那个宏放进去并且得到一个你正在重新定义std的错误,这意味着某人,在某个地方已经做了#define std。把#undef std放在你的include后面,然后找到并射杀将std定义为宏的人。

标签: c++ visual-studio-2010 c++11 std tr1


【解决方案1】:

根据您的 cmets 和 this page,我认为 Marmalade 带有它自己的 STL 实现,这似乎已经过时了。 This page 验证他们使用的是 STLPort 的版本,它不支持 2005 年推出的 TR1,更不用说任何更新的东西了。您的选择是:

1) 自己复制/编写这些
2) 不用
3)Download a newer version of STLPort。最近两年似乎没有更新,所以没有 C++11,但他们确实提到了 functional,但不清楚它是否在 stdstd::tr1 命名空间中.但是,这可能不适用于 Marmalade,因此请做好备份并小心。

【讨论】:

  • 我认为它只是与 STLPort (source) 捆绑在一起......太糟糕了。
  • @Speed:更新的答案,新版本的 STLPort可能对您有帮助,也可能对您没有帮助
  • 感谢您的扩展帮助。我真的很感激!
  • 图书馆到底为什么要这样做?
【解决方案2】:

Visual Studio 2010 附带默认启用的 C++11(或至少已实现)。您需要使用std::function&lt;void(void)&gt;

获取完整表格see here

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

【讨论】:

  • 无论如何,我仍然得到完全相同的错误。 std::function&lt;void(void)&gt; callback; 返回确切的错误,没有第一个错误:error C2039: 'function' : is not a member of '_STL'
  • @Speed 这看起来非常可疑。 grep 查找任何奇怪的defines
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
相关资源
最近更新 更多