8

How does one start using the tr1 features of Visual Studio 2010? For a more specific case, I require the std::tr1::function. I tried including #include <tr1/functional> which reports as missing, while #include <functional> includes fine, but when I set this:

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.

As suggested, skipping the tr1, still returns the same result:

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 ';'
Speed
  • 1,424
  • 1
  • 16
  • 24
  • 4
    `tr1` stands for [Technical Report 1](http://en.wikipedia.org/wiki/C%2B%2B_Technical_Report_1) which was a list of proposed additions to the C++ Standard. Once the proposals were accepted, the `tr1` designation became obsolete. – Mark Ransom May 01 '12 at 19:21
  • did you `include `? – Mooing Duck May 01 '12 at 19:29
  • 1
    The error says functional is not a member of _STL. Are you sure you wrote `std::function`, and not `std::functional`? – bames53 May 01 '12 at 19:31
  • Copied the wrong error. I tried both versions, both with the same result. – Speed May 01 '12 at 19:33
  • @Speed : Do you have `#define std _STL` somewhere? Because that error makes no sense for the code you've shown. – ildjarn May 01 '12 at 19:35
  • No, I do not. However if I put that in, I get a completely third error saying I am redefining std. – Speed May 01 '12 at 19:36
  • @Speed: Works for everyone else: http://ideone.com/9gd3N, there's something missing that you haven't told us. Especially since your compiler seems to think someone redefined `std` as a variable of type `_STL`. – Mooing Duck May 01 '12 at 19:37
  • It may be the library. I am using a library called Marmalade with it. It may tinker with the settings of the project... – Speed May 01 '12 at 19:39
  • Comment out all the includes except functional includes, and see if the errors go away on the line with the `std::function`. If so, you know it's a header causing the problem. – Mooing Duck May 01 '12 at 19:41
  • 2
    @Speed If you put that macro in and get an error that you're redefining `std`, that means someone, somewhere already does `#define std`. Put `#undef std` after your includes, then find and shoot whoever defined `std` as a macro. – ildjarn May 01 '12 at 19:41
  • to help with ildjarn's guess: CTRL+SHIFT+F. Find: "define std", Look in: "Entire Solution" – Mooing Duck May 01 '12 at 19:43
  • There is no matches as I do not do that in the code. I think the library http://www.madewithmarmalade.com/ is using a modified compiler... – Speed May 01 '12 at 19:44
  • @Speed : Did you or did you not try `#undef std`? – ildjarn May 01 '12 at 19:45
  • @Speed: Did you try commenting out various headers to see which is causing the `functional` issue? – Mooing Duck May 01 '12 at 19:46
  • undefining std breaks strings and vectors. Marmalade tinkers with those classes. I am sure of it... – Speed May 01 '12 at 19:51
  • @Speed: http://www.madewithmarmalade.com/marmalade/benefits/richer-cross-platform-native-apps says they compile with Visual C++ – Mooing Duck May 01 '12 at 19:51
  • They do, but the Visual Studio project gets generated by their bat file. – Speed May 01 '12 at 19:52
  • waaaaaiiiit, Does `Marmalade` provide it's own standard library? I think it does. That would explain the lack of newer features, like `function`. – Mooing Duck May 01 '12 at 19:52
  • http://www.madewithmarmalade.com/devnet/forum/4994 I guess so. – Speed May 01 '12 at 19:53
  • I'll try taking the std::function files and put them directly into my source folder... Thank you for your time :( – Speed May 01 '12 at 19:54

2 Answers2

8

Based on your comments, and on this page, I think that Marmalade comes with it's own STL implementation, that appears out of date. 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. Your options are:

1) Copy/write those yourself
2) Do without
3) Download a newer version of 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. However, this might not work with Marmalade, so make backups and be careful.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Mooing Duck
  • 64,318
  • 19
  • 100
  • 158
2

Visual Studio 2010 ships with C++11 enabled by default (or at least what is implemented). You need to use std::function<void(void)>.

For a complete table see here.

As an aside: You shouldn't use anything from TR1 nowadays. It has been integrated into the new standard.

pmr
  • 58,701
  • 10
  • 113
  • 156
  • 1
    Regardless, I still get the exact same error. `std::function callback;` returns the exact error, without the first one: `error C2039: 'function' : is not a member of '_STL'` – Speed May 01 '12 at 19:25
  • 1
    @Speed This looks highly suspicious. grep for any strange `defines`. – pmr May 01 '12 at 19:40