template <class T>class A{public: template <class U> static U foo(T* p) { p; return U(); }};class B{ /*template <class T> template <class U> frIEnd U A<T>::foo<U>(T*);*/ frIEnd B A<B>::foo<B>(B*); B() {}public:};...A<B>::foo<B>(nullptr);
而且效果很好.但是我没有做过的事情被评论:
/*template <class T>template <class U>frIEnd U A<T>::foo<U>(T*);*/
我不知道我应该使用什么语法来使它工作.所以我需要将我的朋友声明推广到所有可能的类型.我已经尝试了很多语法变体但没有成功.有人可以指出我应该写什么而不是我的注释代码才能使它有效?
谢谢!
template <class T>template <class U>frIEnd U A<T>::foo(T*);
以下适用于IDeOne.com
#include <iostream>template <class T>class A{public: template <class U> static U foo(T* p) { p; return U(); }};class B{ template <class T> template <class U> frIEnd U A<T>::foo(T*); B() {}public: voID hello() const { std::cout << "I'm a B!" << std::endl; }};int main(int,char*[]){ A<B>::foo<B>(NulL).hello();}总结
以上是内存溢出为你收集整理的c – 模板类的朋友模板功能全部内容,希望文章能够帮你解决c – 模板类的朋友模板功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)