views:

130

answers:

3
+1  Q: 

recursive typedef

Is the following allowed?

typedef Foo<Bar> Bar;

My compiler complains that 'class Bar' has a previous declaration as 'class Bar'.

+2  A: 

If Bar is a class as a template parameter for Foo, it can't be the typedefed Foo<Bar> at the same time.
You would be redeclaring Bar, first as a standalone class and then as a template instantiation, but even typedef Foo<Whatever> Bar; wouldn't work if you have already declared Bar as a class.

Arkaitz Jimenez
+5  A: 

What you are doing is the equivalent of:

struct A {};
struct B {};
typedef A B;

which not suprisingly is not legal.

anon
Typedefs and classes are not in different namespaces in C++, thus it's not legal in C++.
Johannes Schaub - litb
A: 

No it is not allowed.

Max Lybbert