Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 725
Johan Hjalmarsson Avatar asked Jan 21 '26 21:01

Johan Hjalmarsson


1 Answers

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()
{
}
  • http://ideone.com/9mCaq0 (C++) error: expected nested-name-specifier before ‘Word_List’
  • http://ideone.com/FdIKcr (C++11) success

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

like image 159
FredericS Avatar answered Jan 24 '26 13:01

FredericS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!