VS03: overloaded non-member operator(<<) for templated class

J

Jacob Foshee

Greetings,
Using MS Visual C++ .NET 2003, I have the following:

template <class T>
class vector3 {
// ...
friend ostream& operator<<(ostream&, const vector3<T>& ); // ostream
operator
}:

template <class T>
ostream& operator<<(ostream& o, const vector3<T>& u ) {
return o << u.x << ", " << u.y << ", " << u.z;
}

/////////////////////////////////
I cannot get this to link w/ VS03. (It can't find the operator)
From what I have been told, this runs under VS02. I get the same problem
for unary minus. Any ideas?

Thanks very much,
Jacob Foshee
 
D

David White

Jacob Foshee said:
Greetings,
Using MS Visual C++ .NET 2003, I have the following:

You didn't show the header files that you must be including.
template <class T>
class vector3 {
// ...
friend ostream& operator<<(ostream&, const vector3<T>& ); // ostream
operator

ostream is in the 'std' namespace. I assume you have a 'using' somewhere
that you haven't shown, or you are using non-standard headers.
}:
};


template <class T>
ostream& operator<<(ostream& o, const vector3<T>& u ) {
return o << u.x << ", " << u.y << ", " << u.z;
}

/////////////////////////////////
I cannot get this to link w/ VS03. (It can't find the operator)

I have no idea what VS03 is.

Apart from what I've mentioned I don't see anything wrong. The above code,
with corrections and a 'main' added, compiles and links in a VC++ 7.0
console application.
From what I have been told, this runs under VS02.

I have no idea what VS02 is.
I get the same problem for unary minus. Any ideas?

No, none. Perhaps a VC++ newsgroup would be more suitable. This one is for
discussion of standard C++ only.

DW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top