When I write a friend declaration like this
template<typename T>
struct Foo {};
struct Bar {
friend class Foo<Bar>;
};
everything is fine. However, when I use a typedef
template<typename T>
struct Foo {};
struct Bar {
typedef Foo<Bar> FooBar;
friend class FooBar;
};
gcc (4.4.7) complains with
error: using typedef-name ‘Bar::FooBar’ after ‘class’
error: ‘Bar::FooBar’ has a previous declaration here
error: friend declaration does not name a class or function
I always thought a typedef
behaves exactly the same as if I typed the original type.... Is it not allowed to use a typedef
here? or am I just using it wrong?
PS: the template turned out to be a red herring, the following will cause the same error
struct Foo{};
struct Bar{
typedef Foo FooBar;
friend class FooBar;
};