开发者

How to declare a templated struct/class as a friend?

开发者 https://www.devze.com 2023-01-07 22:11 出处:网络
I\'d like to do the following: template <typename T> struct foo { template <typename S> friend struct foo<S>;

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开发者_StackOverflow社区 instantiations of template struct foo friends of foo<T> for all T.

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.


template<typename> friend class foo

this will however make all templates friends to each other. But I think this is what you want?

0

精彩评论

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