This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC 3.4.0: a derived class can't access the data member of a template base class
- From: "Frank Chow" <fzhou at mtone dot com dot cn>
- To: gcc-bugs at gcc dot gnu dot org <gcc-bugs at gcc dot gnu dot org>
- Date: Mon, 21 Jun 2004 17:9:27 +0800
- Subject: GCC 3.4.0: a derived class can't access the data member of a template base class
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).