Archived

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

glaskows

Why do i get this error.

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
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