2

I'm working on a school lab and in the instruction it says:

Change the typedef that defines Word_List to a alias declaration (using)

From what I've googled, the way to do this is to change from:

typedef vector<Word_Entry> Word_List;

to:

using Word_List = std::vector<Word_Entry>;

but when I compile, I get the following error:

error: expected nested-name-specifier before 'Word_List'

Most of the code:

#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <fstream>
#include <cctype>
#include <iomanip>

using namespace std;

struct Word_Entry
{
  string ord;
  unsigned cnt;
};

//typedef vector<Word_Entry> Word_List; <-This is what it used to look like
using Word_List = vector<Word_Entry>;


int main()
{
 ...
}

aditional info:

Yes, I am compiling with c++11 
Word_Entry is a struct that stores 2 variables
I have the line "using namespace std;" in the begining of my code
I'm using mingw compiler
Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64
  • 1
    Did you enable c++11 specification on your project or makefile? – masoud Feb 21 '13 at 15:30
  • I've added aditional info answering your questions – Johan Hjalmarsson Feb 21 '13 at 15:50
  • Could you post the whole file (or a simplified version of it that has the same error)? Theres not quite enough information to tell whats wrong. – Edward A Feb 21 '13 at 15:54
  • Doesn't the `using` keyword operate on namespaces exclusively? I don't think you can use it for complete typedefs. –  Feb 21 '13 at 16:01
  • And inside the main? How are you trying to use it? Also, open up a cmd and do a `g++ --version` and add the output (the relevant line with version not the copyright bit). – Edward A Feb 21 '13 at 16:06
  • As @H2CO3 said, I don't think it's supposed to work like that: http://stackoverflow.com/questions/6973161/c-using-keyword – Mihai Todor Feb 21 '13 at 16:08
  • 2
    @MihaiTodor It actually is supposed to work like that, its called [type-alias](http://en.cppreference.com/w/cpp/language/type_alias). – Edward A Feb 21 '13 at 16:13
  • What version is your MinGW? (first line in g++ --version) – milleniumbug Feb 21 '13 at 16:29

1 Answers1

7

You can see the solution here:

#include <string>
#include <vector>

using namespace std;

struct Word_Entry
{
  string ord;
  unsigned cnt;
};

//typedef vector<Word_Entry> Word_List; <-This is what it used to look like
using Word_List = vector<Word_Entry>;


int main()
{
}

You have a configuration error, you are not compiling with C++11 specification.

Zachi Shtain
  • 826
  • 1
  • 13
  • 31
FredericS
  • 413
  • 4
  • 9
  • 1
    I believe g++ only supports this since version 4.7. [test with 4.7.2](http://liveworkspace.org/code/sgxSh$0), [test with 4.6.3](http://liveworkspace.org/code/sgxSh$1) –  Feb 21 '13 at 16:29