unresolved extern symbol on template member functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have just installed VC++2005 Express Ed. and I keep getting a LNK2001
error:unresolved external symbol "public: virtual void __thiscall
Circle::draw(void)const " (?draw@Circle@@UBEXXZ)
when building the following code:

class Coord {
private:
int x, y;
public:
Coord (int i1, int i2) : x(i1), y(i2) {}
};
class GeoObj {
public:
// draw geometric object:
virtual void draw() const = 0;
};

// concrete geometric object class Circle
// - derived from GeoObj
class Circle : public GeoObj {
public:
virtual void draw() const;
};

// draw any GeoObj
void myDraw (GeoObj & obj)
{
obj.draw(); // call draw() according to type of object
}

int main()
{
Circle c;
myDraw(c); // myDraw(GeoObj&) => Circle::draw()
return 0;
}

Thanks
Eugene
I did unsuccessfully try all the prescribed remedies. Any ideas?
 
Eugene said:
I have just installed VC++2005 Express Ed. and I keep getting a
LNK2001 error:unresolved external symbol "public: virtual void
__thiscall Circle::draw(void)const " (?draw@Circle@@UBEXXZ)
when building the following code:

class Coord {
private:
int x, y;
public:
Coord (int i1, int i2) : x(i1), y(i2) {}
};
class GeoObj {
public:
// draw geometric object:
virtual void draw() const = 0;
};

// concrete geometric object class Circle
// - derived from GeoObj
class Circle : public GeoObj {
public:
virtual void draw() const;
};

// draw any GeoObj
void myDraw (GeoObj & obj)
{
obj.draw(); // call draw() according to type of object
}

int main()
{
Circle c;
myDraw(c); // myDraw(GeoObj&) => Circle::draw()
return 0;
}

Thanks
Eugene
I did unsuccessfully try all the prescribed remedies. Any ideas?

Well, you haven't provided any definition for Circle::draw, so it's not
surprising that it comes up undefined at link time. What does this have to
do with template member functions though? There's not a single template in
the code you've posted...

-cd

PS: virtual void draw const {} would be a definition. What you have is
just a declaration.
 
Back
Top