If I compile the above code in below Linux release ,
>>cat /proc/version
Linux version 2.6.32-573.18.1.el6.x86_64 (mockbuild@x86-010.build.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Wed Jan 6 11:20:49 EST 2016
The code compilation fails with below error :
>>g++ myfile.C -g -o myfile -o myfile -I/usr/include/c++/4.4.4 -I/usr/include/c++/4.4.4/x86_64-redhat-linux/32 -fno-implicit-templates
In file included from myfile.C:2:
myinc.h: In member function ‘List<T>* class_C<T>::theList()’:
myinc.h:34: error: ‘theLizt’ was not declared in this scope
Any Idea what is the issue for above? To summarize the above code .
A class object 'theLizt' declared in public scope of base Class A . Class A ,template Class B and template Class C are in multi-level inheritance.
The class object 'theLizt' is returned from class C's M.F which is an overriding M.F.
in case you wonder why, note that there is no error in class_B, which derives from the non-template class_A. The error is in class_C which derives from a template class_B<T>.
The reason is that it's possible to specialize class_B later in your program, providing a different specialization that doesn't derive from class_A and defines theLizt as something totally different, or doesn't define it at all.
adding this-> or class_C:: before the name makes it dependent - it tells the compiler to postpone deciding how to compile this function until it knows T in class_C<T>, which will happen at the point of use of this template.