Re: I would appreciate some help with template overloading
PAUL BAKER wrote:
typedef unsigned short int doublebyte;
#include <stdint.h>
typedef uint16_t doublebyte;
typedef class ptr_array< char>* char_ptr_array_ptr;
typedef class ptr_array< int>* int_ptr_array_ptr;
typedef class ptr_array< double>* dbl_ptr_array_ptr;
If you prefix that with a declaration of said class template:
template<typename T> class ptr_array;
then you can use typedefs like this:
typedef ptr_array<char>* char_ptr_array_ptr;
cfile.cpp
template< class T>
ptr_array< T> :: ptr_array( T* t_member)
{
append( t_member);
}
Take a look at the C++ FAQ at parashift's, this will lead to linker problems
when stored in a separately compiled .cpp file. Also, you probably can't
append anything without first having initialised the array...
class ptr_array< int> :: ptr_array( char* str)
{...}
This needs to be prefixed with "template <>". Also, how about making 'str'
constant?
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
I'm not sure if anybody is still using Watcom for C++ (I know they recently
open-sourced it, but I don't know if it's usable) so the code that compiler
accepts might *ahem* vary a lot. Now, instead of using anything remotely
modern, you want to switch to a pre-standard compiler that isn't even
supported by the vendor anymore. Sorry, but such a task is IMHO futile.
If you can't spend too much on a compiler, grab e.g. the free version of MS'
Visual Studio or DevC++, both feature a good compiler with an IDE.
Also, consider dumping the whole code or to prepare for some serious
refactoring, because it violates several coding guidelines and looks to me
extremely fragile. It could be that it isn't that bad though and that it's
just that you cut'n'pasted just some excerpts that made it look bad. I'm
suspicious though that the code doesn't hold much water.
Good luck!
Uli