Re: I would appreciate some help with template overloading
"PAUL BAKER" <pabind@ameritech.net> wrote in message
news:upmb3RzBHHA.992@TK2MSFTNGP03.phx.gbl...
I am trying to compile a program that compiled an ran under
Watcom 11c but gives me an overloaded operator error under
Visual Studio 6.0
Any help would be greatly appreciated
I gave an abbreviated version of the class.
Please let me know if anything else is needed to resolve.
If the header snippet you posted is an accurate representation of the actual
code, you have an order problem - the definition of the ptr_array template
must com before the typedefs that make use of it.
Your code is making use of pre-standard (8+ years out of date) syntax for
defining template specializations. You apparently left out too much code in
making your sample, as several functions referenced by the code you posted
are not included.
Can you move to a more recent version of VC? VC6 is going on 10 years old,
is unsupported, and has many warts where templates are concerned.
Here's a revised version of your code that's standard C++ compliant. I
don't know if VC6 will coimpile it - I haven't run VC6 for at least 3 years.
template< class T>
class ptr_array {
private:
T** member;
int count;
public:
int append( T t_member);
int append( char* str);
ptr_array(T*);
ptr_array(char*);
};
typedef ptr_array< char>* char_ptr_array_ptr;
typedef ptr_array< int>* int_ptr_array_ptr;
typedef ptr_array< double>* dbl_ptr_array_ptr;
template< class T>
ptr_array< T> :: ptr_array( T* t_member)
{
append( t_member);
}
template<>
ptr_array< int> :: ptr_array( char* str)
{
int t_member = atoi( str);
append( t_member);
}
template<>
ptr_array< double> :: ptr_array( char* str)
{
double t_member = atof( str);
append( t_member);
}
-cd