开发者

recursive typedef

开发者 https://www.devze.com 2023-01-02 16:46 出处:网络
Is the following allowed? typedef Foo<Bar> Bar; My compiler complains that \'开发者_运维技巧class Bar\' has a previous declaration as \'class Bar\'.What you are doing is the equivalent of:

Is the following allowed?

typedef Foo<Bar> Bar;

My compiler complains that '开发者_运维技巧class Bar' has a previous declaration as 'class Bar'.


What you are doing is the equivalent of:

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

which not suprisingly is not legal.


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.


No it is not allowed.

0

精彩评论

暂无评论...
验证码 换一张
取 消