本文介绍了可能的编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个模板类,它实例化模板的变量 参数类型如下: template< class T> struct TemplateClass { T t; }; struct TestClass { int x; static TemplateClass< TestClass> v2; }; 在Visual C ++ 7下我收到以下编译错误: 错误C2079:''TemplateClass< T> :: t''使用未定义的struct''TestClass''和 [T = TestClass] 然而,它在Borland编译器下编译得很好。 这是Visual C ++编译器中的错误吗? 我将不胜感激。 [见 http://www.gotw.ca/resources/clcm .htm 有关的信息] [comp.lang.c ++。版主。第一次海报:做到这一点! ] 解决方案 这绝对可以用borland编译器编译,但我想知道是什么 规则是这样的,因为 TestClass在模板实例化时没有完全定义?同样的事情 如果没有静态就行不通 - 但是没有模板就可以了。 根本不起作用。 David I have a template class that instantiates a variable of the templateparameter type as follows: template <class T>struct TemplateClass{T t;}; struct TestClass{int x;static TemplateClass<TestClass> v2;}; Under Visual C++ 7 I get the following compiler error:error C2079: ''TemplateClass<T>::t'' uses undefined struct ''TestClass'' with[ T=TestClass ] However, it compiles fine under the Borland compiler. Is this a bug in the Visual C++ compiler? I would appreciate any comments. [ See http://www.gotw.ca/resources/clcm.htm for info about ][ comp.lang.c++.moderated. First time posters: Do this! ] 解决方案 Quite possible. Try it with VC++ v 7.1. V Quite possible. Try it with VC++ v 7.1. V That definitely does compile with the borland compiler, but I am wondering whatthe rules are for this sinceTestClass isn''t fully defined when the template is instantiated? Same thingdoesn''t work without the ''static'' - but doing the equivalent without a templatedoesn''t work at all. David 这篇关于可能的编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 08:17