-1

(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) :-(

Gaurav
  • 794
  • 2
  • 11
  • 32
  • 1
    Can you provide some more details? What compilers are you using? What error messages are you getting? – templatetypedef Feb 04 '11 at 08:55
  • 2
    Is there a question in there somewhere? – Johann Gerell Feb 04 '11 at 08:56
  • 1
    Could you please post more details about `CntrCls1` and `CntrCls2`? – Vlad Feb 04 '11 at 08:57
  • 7
    Why don't you put together the smallest example program you can that actually demonstrates the error, and then list the exact compiler message? – Tony Delroy Feb 04 '11 at 09:06
  • @Vlad and @template Updated the question with additional info. Basically I am using the same compiler (VS 2008) and using roguewave containers – Gaurav Feb 04 '11 at 09:08
  • @Gaurav: could it possibly be that on the second computer the types are actually the same (one is typedefed to another)? Or one is derived from other? (I've got no experience with roguewave containers.) – Vlad Feb 04 '11 at 09:13
  • @Tony The error I am getting on compiler won't help basically CntrlCls2 requires its element class to overload comparison operator (i.e. <) which is not the case thus giving the compiler error but the basic problem is incorrect instantiation of the template function. – Gaurav Feb 04 '11 at 09:16
  • @Vlad I checked for that but to best of my knowledge they are unrelated :-( – Gaurav Feb 04 '11 at 09:19
  • Are the compiling parameters exactly the same? – BЈовић Feb 04 '11 at 09:28
  • Seems to be working on g++: http://www.ideone.com/ETVjw Do `Class` (instead of `class`) in templates declaration is a typo? – Pawel Zubrycki Feb 06 '11 at 14:32
  • 1
    Try explicitly castin &ABC to `CntrCls1<*>` before calling the function, to verify that it really is that type. If that fails, try doing a make-clean on both boxes and rebuilding. – Brent Arias Feb 07 '11 at 04:00
  • @Brent I tried casting it but the result was same. – Gaurav Feb 07 '11 at 04:16
  • 1
    In VS2008, check in the about dialog that they are exactly the same build number. VS2008 has service packs that fixes compiler bugs. – shoosh Feb 07 '11 at 09:09
  • 1
    have you checked #include paths? or maybe there is some #if that excludes the second overload from compilation... You can also try to enable "Preprocess to a file" to see what the compiler is really trying to compile – Loghorn Feb 08 '11 at 12:50
  • Please provide an *entire* minimal code snippet that reproduces the problem you're having. Until you do that, we're all just guessing. – j_random_hacker Feb 12 '11 at 16:02

1 Answers1

0

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.

BloodAxe
  • 833
  • 9
  • 10