如何将 tr1 与 Visual Studio 2010 (tr1::function) 一起使用

How to use tr1 with Visual Studio 2010 (tr1::function)?

本文关键字:tr1 function 一起 2010 Visual Studio      更新时间:2023-10-16

如何开始使用Visual Studio 2010的tr1功能?对于更具体的情况,我需要 std::tr1::函数。我尝试包括#include <tr1/functional>哪些报告为丢失,而#include <functional>包括很好,但是当我设置它时:

std::tr1::function<void(void)> callback;

我得到:

1>d:marmaladeprojectscoresrcbutton.h(21): error C3083: 'tr1': the symbol to the left of a '::' must be a type
1>d:marmaladeprojectscoresrcbutton.h(21): error C2039: 'function' : is not a member of '_STL'
1>d:marmaladeprojectscoresrcbutton.h(21): error C2143: syntax error : missing ';' before '<'
1>d:marmaladeprojectscoresrcbutton.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:marmaladeprojectscoresrcbutton.h(21): error C2238: unexpected token(s) preceding ';'

如果我使用 boost,它可以正常工作,但对于这个项目,由于使用特定的框架,我需要 Visual Studio tr1 版本。

正如建议的那样,跳过 tr1,仍然返回相同的结果:

std::function<void(void)> callback;
1>d:marmaladeprojectscoresrcbutton.h(20): error C2039: 'function' : is not a member of '_STL'
1>d:marmaladeprojectscoresrcbutton.h(20): error C2143: syntax error : missing ';' before '<'
1>d:marmaladeprojectscoresrcbutton.h(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:marmaladeprojectscoresrcbutton.h(20): error C2238: unexpected token(s) preceding ';'

根据您的评论,以及在此页面上,我认为 Marmalade 附带了它自己的 STL 实现,这似乎已经过时了。 此页面验证他们是否使用了STLPort版本,该版本不支持2005年推出的TR1,更不用说更新的版本了。 您的选择是:

1)自己
复制/编写2)不做
3) 下载较新版本的STLPort。 它似乎在过去两年中没有更新,所以没有 C++11,但他们确实提到有 functional ,但不清楚它是在 std 还是std::tr1命名空间中。 但是,这可能不适用于果酱,因此请进行备份并小心。

>Visual Studio 2010附带默认启用C++11(或至少是实现的内容)。您需要使用std::function<void(void)> .

有关完整表格,请参见此处。

顺便说一句:现在你不应该使用 TR1 中的任何内容。它已被整合到新标准中。