Public Group

# Defining virtual functions.

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

## Recommended Posts

I have a base class called Bone and an inherited class called bBone. Bone has the virtual function Draw(), but when I go to define Draw() for bBone in the implementation file I get
error C2509: 'Draw' : member function not declared in 'bBone'
This is how I'm defining Draw for bBone
void bBone::Draw(ID2D1SolidColorBrush *Black){
stuff
}


My tutorial has the definition as part of the declaration so I don't know how to do it separately. [Edited by - Waterfox on March 20, 2010 10:37:08 PM]

##### Share on other sites
To make sure we are on the same page, do we have:

Bone.h
class Bone{  public:    virtual void Draw( ID2D1SolidColorBrush *Black );};

bBone.h
class bBone : public Bone{  public:    void Draw( ID2D1SolidColorBrush *Black );};

bBone.cpp
void bBone::Draw( ID2D1SolidColorBrush *Black ){}

##### Share on other sites
From the sound of things, it seems like you didn't declare it. For that see yaustar's post with bBone.h.

##### Share on other sites
Ahh, I see. I didn't declare it in bBone, I thought it would of automatically done that since it was inherited.
Thanks!

##### Share on other sites
Now I have a new problem, as soon as I define my constructor for bBone I get
1>stick.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Bone::Draw(void)" (?Draw@Bone@@UAEXXZ)

declarations
class Bone{protected:	ID2D1EllipseGeometry *dot;	float angle;	D2D1_MATRIX_3X2_F matrix;	BOOL hit;public:	virtual void Draw();};class bBone:public Bone{public:	bBone();	void Draw(ID2D1SolidColorBrush *Black);};

definitions
void bBone::Draw(ID2D1SolidColorBrush *Black){stuff}bBone::bBone(){stuff}

[Edited by - Waterfox on March 20, 2010 11:01:34 PM]

##### Share on other sites
I'm pretty sure that means the compiler can't find the definition for bone's draw function.

Make sure you define the Draw function for bone.

##### Share on other sites
It definitely can find the definition, it's just that error pops up as soon as I define bBone's constructor.

##### Share on other sites
Quote:
 Original post by WaterfoxIt definitely can find the definition, it's just that error pops up as soon as I define bBone's constructor.

Quote:
 I'm pretty sure that means the compiler can't find the definition for bone's draw function.Make sure you define the Draw function for bone.

Quote:
 public: virtual void __thiscall Bone::Draw(void)

Bone (the base class), not bBone (the derived class). The base class is not abstract, so it needs definitions too.

The reason you don't see the error until you've defined bBone's constructor is that otherwise it doesn't get that far in the error-checking process.

##### Share on other sites
oops, my bad. Everything's fine now, thanks everyone.

##### Share on other sites
New problem :(
I have a vector of Bones containing a Bone and a bBone, but when I iterate the Draw function through the vector, bBone does Bone's Draw function. I've defined both to have different Draw functions though.

• 10
• 17
• 9
• 14
• 41