How to declare a templated struct/class as a friend?
31,175
template<typename> friend class foo
this will however make all templates friends to each other. But I think this is what you want?
Author by
Alexandre C.
Updated on March 30, 2020Comments
-
Alexandre C. about 4 years
I'd like to do the following:
template <typename T> struct foo { template <typename S> friend struct foo<S>; private: // ... };
but my compiler (VC8) chokes on it:
error C3857: 'foo<T>': multiple template parameter lists are not allowed
I'd like to have all possible instantiations of
template struct foo
friends offoo<T>
for allT
.How do I make this work ?
EDIT: This
template <typename T> struct foo { template <typename> friend struct foo; private: // ... };
seems to compile, but is it correct ? Friends and templates have very unnatural syntax.
-
Mr.Anubis over 12 yearscan you please post reference section to standard where it's defined?
-
Muhammad about 10 yearsIn C++03 in 14.5.3.3 and 14.5.3.4, In C++11 you need to read the Friends section in 14.5.4