Search code examples
c++c++11aliastypedefusing

alias using vs typedef


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

Solution

  • 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.