Advertisement

Vector class help

Started by April 22, 2003 01:32 PM
1 comment, last by Slickfty2 21 years, 10 months ago
I''m using the VECTOR class from one of the NeHe lessons. It has all arithmetic operators overloaded, but when I try to do: vec1 = vec2 - vec3; I tells me undefined reference to VECTOR::operator-(VECTOR const&). The operators are defined as inline, but I don''t really think that has anything to do with it. I also added an operator= so that I could do the assignment. Help? Thanks
With inline operators, I don''t think you can prototype them in a class, I think you hae to do like this:

class VECTOR {
public:
...
...

inline operator-(VECTOR v) { ... }

And not

class VECTOR {
public:
...
...

inline operator-(VECTOR v);

And then in another file:

inline operator-(VECTOR v) { ... }
Advertisement
Well, I found one problem. You can either do

inline int foo(...) {...} //in .h file

or

int foo(...); //in .h
and
inline int foo(...)
{...} //in .cpp

but when I took the inline declaration out of the .h file it didn''t get rid of the undefined reference error.

Thanks tho

This topic is closed to new replies.

Advertisement