Compilation Issue across AIX and Linux

Hi ,
I have below code snippet :
>>cat myinc.h
#include <iostream>
class not_Defined;

class class_A {
public :
friend class not_Defined;
not_Defined* theLizt;
};

template <class T>
class List : public class_A {
public:
List();
List(const List<T>&);
~List();

};

template <class T>
class class_B : public class_A {
public :
List<T>* theList() { return (List<T>*)theLizt; }

};

template <class T>
class class_C : public class_B<T> {
public :
List<T>* theList() { return (List<T>*)theLizt; }

};


>>cat myfile.C
#include <iostream>
#include "myinc.h"

using namespace std;

class mainclass {
int number;
};

int main()
{
mainclass mobj;
cout<<"Hello World";
}

If I compile the above code in IBM AIX 6.1 using XLC compiler, it works fine , compiles and links and create a binary and executes fine.

e.g :
$ /compiler/xlc11/usr/vacpp/bin/xlC -g -q32 -qpic=small -qtempinc -I/compiler/xlc11/usr/vacpp/include -I/compiler/xlc11/usr/vac/include -I/usr/include myfile.C -o myfile
$ ./myfile
Hello World$


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.


I guess it's too much to search from
use this->theLizt or class_C::theLizt
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.

Because of that possibility, unqualified lookup of non-dependent names never visits template bases: see last sentence of http://en.cppreference.com/w/cpp/language/unqualified_lookup#Template_definition

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.
Thanks , it ( this-> or class_C:: ) resolved the issue and the above explanation is concise.
Topic archived. No new replies allowed.