Calogero Napoli
Calogero Napoli

Reputation: 61

Error using alias declaration

I'm trying to compile an easy program that use the alias declaration.

This is the code:

#include <iostream>
using namespace std;
using in = int;

in main ()

 {

   in a = 1;

   cout << a << '\n';

   return 0;

 }

The command I use to compile is g++ -std=c++0x program_name.cxx, using the built-in terminal in Kate on Ubuntu OS. But it doesn't work! Any suggestion? (instead using typedef int in; it works).

Upvotes: 1

Views: 2476

Answers (1)

P.P
P.P

Reputation: 121387

Compile in C++11 mode. Type aliasing is supported only in C++11. I suspect the g++ version that use is older and doesn't fully support c++11, hence fails with c++0x.

Compile with: g++ -std=c++11 file.cpp

and it works.

By the way, it seems to be a terrible idea to alias int in such a way.

Upvotes: 4

Related Questions