小弟真心不会了,求教大神,怎么把一个模板类定义为另一个模板类的友元
小弟请教怎么能定义一个模板类,为另一个模板类的友元;其中为友元的那个模板类的模板参数多于另一个模板类;说的有点不好理解,就如下面例子吧。请大神指教
template<class U, class T>
class Foo {
private:
Bar<T>* b;
};
template<class T>
class Bar {
public:
friend template<class U, class T> class Foo<U,T>; // 报错
friend class Foo;// 报错
friend class Foo<U,T> // 报错
};
[解决办法]
template<class T>
class Bar {
public:
template<class U, T> friend class Foo;
};
template<class U, class T>
class Foo {
private:
Bar<T>* b;
};
[解决办法]
template<class T>
class Bar;
template<class U, class T>
class Foo {
private:
Bar<T>* b;
};
template<class T>
class Bar {
public:
template<class U, class T>
friend class Foo; // 后面照着写
};