0

I thought the new using syntax in C++11 and typedef were equivalent (except for templates). But it seems that with using it is also not possible to declare a class member.

class A {
   //... Public members 
private:
    typedef std::vector<double> vector_double; 
    using vector_int = std::vector<int>;        

    void bar(vector_double& vecDouble); // type can be used
    void foo(vector_int& vecInt); // type can't be used: synatx error
 // ... Possible other private members
}

When I try to use the type vector_int in one of the member functions of class A I get a compiler error: syntax error: identifier 'vector_int'.

Am I doing something wrong here or is defining a member type not possible with using?

evolved
  • 1,850
  • 19
  • 40
  • 6
    What compiler are you using? This should work as expected. If it's `gcc` or `clang`, try `-std=c++11`? – lubgr Jul 10 '19 at 08:57
  • This could be the problem, I use an old Visual Studio compiler which I think only supports some C++11 features. I will check the version. – evolved Jul 10 '19 at 09:01
  • There was a discussion at https://stackoverflow.com/questions/10747810/what-is-the-difference-between-typedef-and-using-in-c11 – Thomas G. Jul 10 '19 at 09:03
  • Although I use Visual Studio 2017 IDE, the _MSC_VER I get with `printf("_MSC_VER : %d \n", _MSC_VER);`is 1600 which is Visual Studio's 2010 compiler version 10.0. I guess this explains the problem. Thanks @lubgr. – evolved Jul 10 '19 at 10:05

0 Answers0