Jump to content
  • Advertisement
Sign in to follow this  
Waterfox

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.

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

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


Link to post
Share on other sites
Advertisement
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 )
{
}


Or is your code different?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Waterfox
It 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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

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