On 24 June 2012 09:46, icegood <icegood1980@xxxxxxxxx> wrote: > > Found partially answer of my question > http://gcc.gnu.org/ml/gcc-help/2006-10/msg00059.html there > i.e. derivatives of template class should use this->x instead of x to be > able to get member x. The problem is that it seems related not only to x but > rather to all members of Der and it precedents i.e. in same example as in > link above: > > template<class T> > class Base > { > protected: > T x; > Base() {} > int DummyBase; > }; > > template <class T> > class Der: public Base<T> > { > public: > using Base<T>::x; > > Der():Base<T>() {} > int get(); > void DoSmth(); > int DummyDer; > }; > > template <class T> void Der<T>::DoSmth() > { > return DummyBase+DummyDer; // compiler shouts that both DummyDer and > DummyBase are out of scope. > } It only complains about DummyBase. This is how C++ works, see http://gcc.gnu.org/wiki/VerboseDiagnostics#dependent_base and the two FAQs it links to. > So, what's the reason for compiler to do so? What means "two pass > compilation of the templates" and why it leads to so unfavorable results? Templates are processed once when defined and again when instantiated and all the types are known. It is only possible to know where the name DummyBase comes from at instantiation time, because there could be a specialization for Base that changes the meaning of DummyBase or fails to define it entirely.