在 Linux 上使用 GCC 4.8.2,我想授予工厂方法 Create() 对 C 类的私有构造函数的访问权限,但是在尝试声明专门的朋友时出现“错误:'Create' 未在此范围内声明” . 如何在不对 B::Create() 的所有类型开放声明的情况下使其工作?
template <typename T> class A {
public:
class B;
template <typename U> class C;
};
template <typename T>
class A<T>::B {
public:
template <typename U> static void Create();
};
template <typename T> template <typename U>
class A<T>::C {
C() = default;
friend void B::Create<U>();
};
template <typename T> template <typename U>
void A<T>::B::Create() {
C<U>{};
}
int main() {
A<int>::B::Create<char>();
}