Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

glaskows

Why do i get this error.

This topic is 5587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(Visual C++ 6.0) main.obj : error LNK2001: unresolved external symbol "public: class vector & __thiscall vector::operator+(class vector const &)" (??H?$vector@M@@QAEAAV0@ABV0@@Z) The 2 important files: ///////////////////// vector.cpp \\\\\\\\\\\\\\\\\\\\ #include "vector.h" template vector vector::operator +(const vector &vec) { vector total(x+vec.x,y+vec.y,z+vec.z); return total; } ////////////////////// vector.h \\\\\\\\\\\\\\\\\\\\\ template class vector { public: vector():x(0),y(0),z(0) {} vector(tipo a, tipo b, tipo c):x(a),y(b),z(c) {} void set(tipo a, tipo b, tipo c) { x=a; y=b; z=c; } tipo getx() { return x; } tipo gety() { return y; } tipo getz() { return z; } vector operator +(const vector&); private: tipo x; tipo y; tipo z; };

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
The above poster is correct. The majority of compilers out on the market right now don''t support the template "export" keyword. Which means you can''t have a .cpp/.h file for templated functions. All implementations of templated functions must be declared in the same file.

Share this post


Link to post
Share on other sites
Just put all your implementation code
in the vector.h like this:

////////////////////// vector.h \\\\\\\\\\\\\\\\\\\\\
template class vector {
public:
vector():x(0),y(0),z(0) {}
vector(tipo a, tipo b, tipo c):x(a),y(b),z(c) {}
void set(tipo a, tipo b, tipo c) {
x=a;
y=b;
z=c;
}
tipo getx() { return x; }
tipo gety() { return y; }
tipo getz() { return z; }
vector operator +(const vector&);
private:
tipo x;
tipo y;
tipo z;
};

...

template
vector vector::operator +(const vector &vec)
{
vector total(x+vec.x,y+vec.y,z+vec.z);
return total;
}

...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!