GCC 3.4.0: a derived class can't access the data member of a template base class
Frank Chow
fzhou@mtone.com.cn
Mon Jun 21 09:10:00 GMT 2004
Windows 2000 sp4
gcc (GCC) 3.4.0 (mingw special)
The following code can not be compiled by gcc (GCC) 3.4.0 (mingw special)
// try.cpp
#include <iostream>
struct B
{
size_t nSize;
};
template <typename T>
struct D : public T
{
D()
{
nSize = sizeof(T);
}
};
using namespace std;
int main()
{
D<B> sth;
cout << sth.nSize << endl;
return 0;
}
(compile instruction)
H:\current2>g++ -o try try.cpp
(output)
try.cpp: In constructor `D<T>::D()':
try.cpp:13: error: `nSize' undeclared (first use this function)
try.cpp:13: error: (Each undeclared identifier is reported only once for each fu
nction it appears in.)
By the way, gcc (GCC) 3.3.1 (cygwin version) can compile this code successfully, so do Visual C++ .Net (cl v 13.10.3077).
More information about the Gcc-bugs
mailing list