Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unusual typedef use in C++

Tags:

c++

typedef

I came across a new use of the keyword typedef in C++.

What does this typedef statement mean ?

int typedef foo; 
like image 475
vivek Avatar asked Sep 20 '11 19:09

vivek


2 Answers

It's the same as

typedef int foo; 

i.e. it defines foo to be the type int. While the grammar allows to swap typedef and int in this case, you usually would not do this because it impairs readability.

like image 68
Sven Marnach Avatar answered Sep 22 '22 14:09

Sven Marnach


typedef is a decl-specifier, so it has the same syntax rules as const or static. It can be moved about like that and will mean the same thing.

like image 28
Jonathan Grynspan Avatar answered Sep 21 '22 14:09

Jonathan Grynspan