Why do i get this error.

Started by
4 comments, last by glaskows 21 years, 1 month ago
(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; };
Advertisement
You need to put templated and inline functions in the file you declared them in.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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.
Can u give me some source, please...
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;
}

...
Thanx u all for ur answers!

This topic is closed to new replies.

Advertisement