可能的编译错误? [英] possible compiler bug?
问题描述
我有一个模板类,它实例化模板的变量
参数类型如下:
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 ++。版主。第一次海报:做到这一点! ]
Eric写道:
我有一个实例化变量的模板类
模板参数类型如下:
[snip]
cat recursive.cc
#include< iostream>
模板< class T>
struct TemplateClass {
T t;
};
< br $>
struct TestClass {
int x;
static TemplateClass< TestClass> v2;
TestClass(int i = 0):x(i){}
};
int main(int argc,char * argv []){
TestClass t;
std :: cout<< t.x = << t.x<< std :: endl;
返回0;
}
g ++ -Wall -ansi -pedantic -o recursive recursive.cc
./recursive
tx = 0
在Visual C ++ 7下我得到以下编译器错误:
错误C2079:''TemplateClass< T> :: t''使用未定义的struct TestClass与
[T = TestClass]
然而,它在Borland编译器下编译得很好。
这是Visual C ++编译器中的一个错误?
我将不胜感激。
Eric写道:我有一个模板类实例化模板
参数类型的变量如下:
template< class T>
struct TemplateClass
{
T t;
{
int x;
静态TemplateClass< TestClass> v2;
};
在Visual C ++ 7下,我收到以下编译错误:
错误C2079:''TemplateClass< T> :: t''使用未定义的struct'' TestClass''与
[T = TestClass]
然而,它在Borland编译器下编译得很好。
这是Visual C ++编译器中的一个错误吗? / blockquote>
很可能。尝试使用VC ++ v 7.1。
V
Victor Bazarov写道:
Eric写道:我有一个模板类,它实例化模板
参数类型的变量,如下所示:
模板< 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 ++编译器中的一个错误吗? / blockquote>
很可能。尝试使用VC ++ v 7.1。
V
这绝对可以用borland编译器编译,但我想知道是什么
规则是这样的,因为
TestClass在模板实例化时没有完全定义?同样的事情
如果没有静态就行不通 - 但是没有模板就可以了。
根本不起作用。
David
I have a template class that instantiates a variable of the template
parameter 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! ]解决方案Eric wrote:
I have a template class
that instantiates a variable of the template parameter type as follows:
[snip]
cat recursive.cc #include <iostream>
template <class T>
struct TemplateClass {
T t;
};
struct TestClass {
int x;
static TemplateClass<TestClass> v2;
TestClass(int i = 0): x(i) { }
};
int main(int argc, char* argv[]) {
TestClass t;
std::cout << "t.x = " << t.x << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o recursive recursive.cc
./recursive t.x = 0
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.
Eric wrote:I have a template class that instantiates a variable of the template
parameter 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?
Quite possible. Try it with VC++ v 7.1.
V
Victor Bazarov wrote:
Eric wrote:I have a template class that instantiates a variable of the template
parameter 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?
Quite possible. Try it with VC++ v 7.1.
V
That definitely does compile with the borland compiler, but I am wondering what
the rules are for this since
TestClass isn''t fully defined when the template is instantiated? Same thing
doesn''t work without the ''static'' - but doing the equivalent without a template
doesn''t work at all.
David
这篇关于可能的编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!