简体   繁体   English

如何将模板化的struct / class声明为朋友?

[英]How to declare a templated struct/class as a friend?

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: 但我的编译器(VC8)扼杀了它:

error C3857: 'foo<T>': multiple template parameter lists are not allowed

I'd like to have all possible instantiations of template struct foo friends of foo<T> for all T . 我想为所有T提供foo<T>template struct foo朋友的所有可能的实例化。

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? 但我认为这就是你想要的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM