This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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).




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]