On Wed, Feb 01, 2006 at 06:08:23PM +0100, Christian Weckmueller wrote: > Hello dear gcc-helper, > > I have a program without problems compiling with 3.3.5 but don't work with > 4.0.2. So here is the question: are there big differences in templates > combined with inheritance between these versions? > > I give you a part of the code: > > template<typename T> class Vector{ > > protected: > T *vectorPtr; > size_type dim; <<<<< > unsigned short coutwidth; > ... > }; > > template<typename T> class NumericVector : public Vector<T>{ > > public: > NumericVector() : Vector<T>(){} > NumericVector(size_type dim) : Vector<T>(dim){} > NumericVector(size_type dim, T initVal) : Vector<T>(dim, initVal){} > NumericVector( const Vector<T> &src ); > > void makeHilb(); > }; > > template<typename T> NumericVector<T>::NumericVector( const Vector<T> &src ) { > > dim = src.length(); <<<<<<< > vectorPtr = NULL; > unsigned short counter = 3; > ... > } > > in the program i use NumericVector. the compiler 4.0.2 says he don't know > dim > in the convertconstructor of NumericVector > > the older one is fine with this program. > > Can anybody explain why there is a problem? > > Thanks, cris Hi, g++ 4.0.2 is right, your code is incorrect: since class template NumericVector uses a *dependant* base class Vector<T>, members of this base class must be qualified. So to get access to dim in that constructor, you need to call it Vector<T>::dim or this -> dim. (A using declaration using Vector<T>::dim; also does the job.) Oliver P.S. Search for "dependant names" in the index of @Book{JV2002, author = {David Vandevoorde and Nicolai M. Josuttis}, title = {C++ Templates: The Complete Guide}, publisher = {Addison-Wesley}, year = 2002, address = {Boston}, month = {November}, note = {ISBN 0-201-73484-2; QA76.73.C153 V37 2003}, annote = {Vorhanden.} }