简体   繁体   English

如何在Visual Studio 2010中使用tr1(tr1 :: function)?

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

How does one start using the tr1 features of Visual Studio 2010? 如何开始使用Visual Studio 2010的tr1功能? For a more specific case, I require the std::tr1::function. 对于更具体的情况,我需要std :: tr1 :: function。 I tried including #include <tr1/functional> which reports as missing, while #include <functional> includes fine, but when I set this: 我尝试将#include <tr1/functional>报告为缺失,而#include <functional>包括罚款,但是当我设置它时:

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

I get: 我明白了:

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 ';'

If I use boost, it works fine, but for this project, because of using a specific framework I'd require the Visual Studio tr1 version. 如果我使用boost,它工作正常,但对于这个项目,由于使用特定的框架,我需要Visual Studio tr1版本。

As suggested, skipping the tr1, still returns the same result: 正如所建议的那样,跳过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 ';'

Based on your comments, and on this page , I think that Marmalade comes with it's own STL implementation, that appears out of date. 根据您的评论,在这个页面上 ,我认为Marmalade附带了它自己的STL实现,它看起来已经过时了。 This page verifies that they use a version of STLPort , that does not support the TR1 that came out in 2005, much less anything newer. 此页面验证他们使用的是STLPort版本,该版本不支持2005年推出的TR1,更不用说更新的版本了。 Your options are: 你的选择是:

1) Copy/write those yourself 1)自己复制/写这些
2) Do without 2)没有
3) Download a newer version of STLPort . 3) 下载更新版本的STLPort It doesn't seem to have been updated in the last two years, so no C++11, but they do mention having functional , but aren't clear as to if it's in the std or std::tr1 namespace. 它似乎在过去两年中没有更新,所以没有C ++ 11,但它们确实提到了functional ,但是不清楚它是否在stdstd::tr1命名空间中。 However, this might not work with Marmalade, so make backups and be careful. 但是,这可能不适用于Marmalade,因此请进行备份并小心。

Visual Studio 2010 ships with C++11 enabled by default (or at least what is implemented). Visual Studio 2010默认启用C ++ 11(或至少实现了什么)。 You need to use std::function<void(void)> . 您需要使用std::function<void(void)>

For a complete table see here . 有关完整的表格, 请参见此处

As an aside: You shouldn't use anything from TR1 nowadays. 暂且不说:现在你不应该使用TR1中的任何东西。 It has been integrated into the new standard. 它已被纳入新标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM