Re: I would appreciate some help with template overloading
This is a multi-part message in MIME format.
------=_NextPart_000_00EF_01C707D1.A2F4F3F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I'm updating a program I wrote 10 years ago to carve tire models on a 5 =
axis machine from 2d geometry. I haven't worked with C/C++ for 10 years =
and my books equally outdated. Are there any books in particular that =
you recomend. I did change the syntax as you recomended and am waiting =
for my visual studio 2005 to arrive.
I forgot to past:
template< class T> class ptr_array;
prior to
typedef class ptr_array< char>* char_ptr_array_ptr;
at the top of headerfile.hpp.
--
Paul Baker
pabind@ameritech.net
"Carl Daniel [VC++ MVP]" =
<cpdaniel_remove_this_and_nospam@mvps.org.nospam> wrote in message =
news:%235LZVhzBHHA.4680@TK2MSFTNGP04.phx.gbl...
"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
------=_NextPart_000_00EF_01C707D1.A2F4F3F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; =
charset=iso-8859-1">
<META content="MSHTML 6.00.5730.11" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial>I'm updating a program I wrote 10 years ago to =
carve tire
models on a 5 axis machine from 2d geometry. I haven't worked with =
C/C++ for 10 years and my books equally outdated. Are =
there
any books in particular that you recomend. I did change the =
syntax as
you recomended and am waiting for my visual studio 2005 to arrive.
</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>I forgot to past:</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial><EM>template< class T> class
ptr_array;</EM></FONT></DIV>
<DIV><FONT face=Arial></FONT><FONT face=Arial></FONT><FONT
face=Arial></FONT><FONT face=Arial></FONT><FONT =
face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>prior to </FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial><EM>typedef class ptr_array< =
char>*
char_ptr_array_ptr;</EM></FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>at the top of headerfile.hpp.</FONT></DIV>
<DIV><FONT face=Arial></FONT><BR>-- <BR>Paul Baker<BR><A
href="mailto:pabind@ameritech.net">pabind@ameritech.net</A></DIV>
<DIV>"Carl Daniel [VC++ MVP]" <<A
href="mailto:cpdaniel_remove_this_and_nospam@mvps.org.nospam">cpdaniel_=
remove_this_and_nospam@mvps.org.nospam</A>>
wrote in message <A
href="news:%235LZVhzBHHA.4680@TK2MSFTNGP04.phx.gbl">news:%235LZVhzBHHA.=
4680@TK2MSFTNGP04.phx.gbl</A>...</DIV>"PAUL
BAKER" <<A =
href="mailto:pabind@ameritech.net">pabind@ameritech.net</A>>
wrote in message <BR><A
href="news:upmb3RzBHHA.992@TK2MSFTNGP03.phx.gbl">news:upmb3RzBHHA.992@T=
K2MSFTNGP03.phx.gbl</A>...<BR>>
I am trying to compile a program that compiled an ran under<BR>> =
Watcom 11c
but gives me an overloaded operator error under<BR>> Visual Studio
6.0<BR>> Any help would be greatly appreciated<BR>> I gave an =
abbreviated
version of the class.<BR>> Please let me know if anything else is =
needed to
resolve.<BR><BR>If the header snippet you posted is an accurate =
representation
of the actual <BR>code, you have an order problem - the definition of =
the
ptr_array template <BR>must com before the typedefs that make use of
it.<BR><BR>Your code is making use of pre-standard (8+ years out of =
date) syntax
for <BR>defining template specializations. You apparently left out =
too
much code in <BR>making your sample, as several functions referenced by =
the code
you posted <BR>are not included.<BR><BR>Can you move to a more recent =
version of
VC? VC6 is going on 10 years old, <BR>is unsupported, and has many =
warts
where templates are concerned.<BR><BR>Here's a revised version of your =
code
that's standard C++ compliant. I <BR>don't know if VC6 will =
coimpile it -
I haven't run VC6 for at least 3 years.<BR><BR>template< class =
T><BR>class
ptr_array {<BR>
private:<BR>
T**
member;<BR>
int =
count;<BR>
public:<BR> int append(
T =
t_member);<BR> int
append( char*
str);<BR><BR>
ptr_array(T*);<BR>
ptr_array(char*);<BR>};<BR><BR>typedef ptr_array< =
char>*
char_ptr_array_ptr;<BR>typedef ptr_array< int>*
int_ptr_array_ptr;<BR>typedef ptr_array< =
double>*
dbl_ptr_array_ptr;<BR><BR><BR><BR>template< class =
T><BR>ptr_array<
T> :: ptr_array( T* =
t_member)<BR>{<BR>
append( t_member);<BR>}<BR><BR>template<><BR>ptr_array< int> =
::
ptr_array( char* str)<BR>{<BR> int =
t_member
= atoi( str);<BR> append(
t_member);<BR>}<BR><BR>template<><BR>ptr_array< double> ::
ptr_array( char* str)<BR>{<BR> =
double
t_member = atof( str);<BR> append(
t_member);<BR>}<BR><BR><BR>-cd<BR><BR></BODY></HTML>
------=_NextPart_000_00EF_01C707D1.A2F4F3F0--