c++ - 拥有自己的类模板和其他模板参数的 friend

标签 c++ templates friend

是否可以将自己的类模板与其他模板参数声明为友元?

template<class T, class... Ts>
class A {
    template<class U> friend class A<U, Ts...>;    //compile error - C3772  'A<U>': invalid friend template declaration 
};

最佳答案

template<class T, class... Ts>
class A {
    template<class U, class... Us> friend class A; //here you go
};

A之后不需要指定模板参数

关于c++ - 拥有自己的类模板和其他模板参数的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36217082/

相关文章:

c++ - 将 CMAKE_C_FLAGS 和 CMAKE_CXX_FLAGS 设置为同一件事而不重复自己?

c++ - 从文件中读取插入值到整数和字符 C++

templates - 在 KnockoutJS 中使用外部模板

c++ - 如何使用 CredUIPromptForWindowsCredentials 验证凭据

c++ - 如何减少大量包装类的实现代码?

C++ unique_ptr 与 friend 类私有(private)析构函数

c++ - 带有默认模板参数的友元函数模板

ios - 使用 iOS SDK 添加好友

c++ - 继承、模板和虚函数(这可能会变得困惑)

javascript - 作为常量存储的模板字符串