本文介绍了模板相关查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个模板化的班级成员函数,呼叫临时成员 另一个班级的功能。 //啊 模板< class T> A级{ 公开: 静态T * create(); }; // Bh B级{ 模板< class T> T * makeData(); }; 模板< class T> T * B :: makeData() { 返回A< T> :: create(); } 当我在某些X.cpp中包含Bh时,我得到一个编译错误(gcc 3.3.6)。 (错误在我包含的行上,而不是我实例化的地方) 。 但是我没有得到gcc 4.2.2的编译错误。有什么方法我可以在gcc3.3.6中避免这个错误吗? 问候, ~SoumenI''ve a templatized class member function calling templatized memberfunction of another class.//A.htemplate <class T>class A {public:static T* create();};//B.hclass B {template<class T>T* makeData();};template<class T>T* B::makeData(){return A<T>::create();}I get a compile error (gcc 3.3.6) when I include B.h in some X.cpp.(Error is on the line where I include, not where I instantiate).But I don''t get compile error with gcc 4.2.2. Is there any way that Ican avoid this error in gcc3.3.6?Regards,~ Soumen推荐答案 小修正A不是模板化的类,而是创建是 模板化的方法。 A类{ public: template< class T> static T * create(); }; 另外,B :: makeData()如下: // Bh class B { public: template< class T> T * makeData(); }; 模板< class T> T * B :: makeData() { 返回A :: create< T>(); }Little correction A is not templatized class, rather create istemplatized method.class A {public:template <class T>static T* create();};Also, B::makeData() is like following://B.hclass B {public:template<class T>T* makeData();};template<class T>T* B::makeData(){return A::create<T>();} 所以它必须怀疑你在那里做错了什么。So it must suspect you''ve done something wrong there. 发布重现错误的确切代码,告诉我们 确切的错误信息,我们可以开始推测 编译器的推理以及它是对还是错。 不要具体,答案可能不会得到更多 特定于我的上面。Post the exact code that reproduces the error, tell us theexact error message, and we can begin to speculate about thecompiler''s reasoning and whether it''s right or wrong.Don''t be as specific, and the answers probably won''t get morespecific than mine from above. SchobiSchobi 所以它必须怀疑你在那里做错了什么。 So it must suspect you''ve done something wrong there. ......或者编译器无法处理代码,因为它是由于错误或误解而导致的错误标准。 没有办法确定。... or the compiler is incapable of processing the code because it ismalfunctioning due to a bug or to a misinterpretation of the Standard.There is no way to tell for sure. 发布重现错误的确切代码,告诉我们 确切的错误信息,我们可以开始推测 编译器的推理以及它是对还是错。 不要具体,答案可能不会得到更多 特定于我的以上。 Post the exact code that reproduces the error, tell us the exact error message, and we can begin to speculate about the compiler''s reasoning and whether it''s right or wrong. Don''t be as specific, and the answers probably won''t get more specific than mine from above. 版本之间的差异很可能是因为编译器开发人员已经赶上了标准或修复了他们的错误中的一些错误> 产品。在GCC论坛中提出这个问题是明智的[ 以及,而不是在这里]。Most likely the difference between versions is because the compilerdevelopers have caught up with the Standard or fixed some bugs in theirproduct. It would be wise to ask this question in the GCC forum [aswell as, not instead of, here]. Schobi Schobi V - 请在通过电子邮件回复时删除资金''A' 我没有回复热门回复,请不要问V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask 这篇关于模板相关查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 21:48