Inconsistent error using template functions

369 views Asked by At

(This question has bounty for anyone willing to take a shot)

Hi I have defined overloading template function with container class as arguments

(Here CntrlCls1 = RWTValOrderedVector and CntrlCls2 = RWTPtrSortedVector)

template<Class X> void func(CntrCls1<X>* ){}

template<Class X> void func(CntrCls1<X*>* ){}

template<Class X> void func(CntrCls2<X>*){}

After defining I am calling function as following

func(&ABC);

where ABC is instance of type CntrCls1<*> (i.e. it is a container of pointers)

Now this is compiling just fine on my computer, but when I compile on a different system, for some reason the compiler is trying to instantiate function template with CntrlCls2 parameter, and as a result giving error.

CtrCls1 and CtrCls2 are unrelated containers.

Update: I am using the VS 2008 to build on both the systems so that shouldn't be a problem.

Update1: I tried to recompile after commenting out function template with CtrCls2 parameter Now the compile is trying to instantiate the first function ( i.e. without pointers) :-(

1

There are 1 answers

0
BloodAxe On

1) Check Service Packs for the VS 2008 installed. Compilator versions can differ on machies, causing different results.

2) Try to use a "typename" keyword instead of "class" in template declaration.

And by the way. From the code i see you're using pointers for values of the sorted container. Sorted containers expects to find the comparison like

template<T> bool operator<(const T&left, const T&right);

Since RWTValOrderedVector and RWTPtrSortedVector looks like containers that contains values in sorted orded they should use such comparison operator. BUT, for pointer types operator< function compares their adresses, not the object they point. So storing pointers in ordered container will give you sorted pointers set, not the set of the pointers to sorted objects. Just FYI.