Defining virtual functions.

Started by
17 comments, last by Waterfox 14 years, 1 month ago
Do you have a vector of bones or a vector of pointers to bones?

std::vector<Bone> foo;

or

std::vector<Bone*> foo;
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Advertisement
A vector of bones.
Quote:Original post by Waterfox
I vector of bones


Well that's why it doesn't do what you expect, its never going to call your bBone::Draw because you're not storing any bBone's in the vector, you're only storing Bone's.

For it to work you'll have to store pointers to Bones in the vector.
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Ahh, I get it. So since I'm pushing back new Bones and bBones, when I want to get rid of the vector will I have to iterate delete through the vector?
You seem to have: virtual void Draw(void); in the the Bone class, and this: virtual void Draw(ID2D1SolidColorBrush *Black); in the bBone class, making them two entirely different calls. Likely this is the reason the Bone::Draw is always called. They must match up, such as both being: void Draw(void).
Quote:Original post by Waterfox
Ahh, I get it. So since I'm pushing back new Bones and bBones, when I want to get rid of the vector will I have to iterate delete through the vector?


Or you use something less error-prone like a Boost pointer container.
Quote:Original post by blackbird04217
You seem to have: virtual void Draw(void); in the the Bone class, and this: virtual void Draw(ID2D1SolidColorBrush *Black); in the bBone class, making them two entirely different calls. Likely this is the reason the Bone::Draw is always called. They must match up, such as both being: void Draw(void).


No. None of the OP's sample code shows these issues but he clearly slices his objects when inserting them into his container.
Quote:Original post by Waterfox
Ahh, I get it. So since I'm pushing back new Bones and bBones, when I want to get rid of the vector will I have to iterate delete through the vector?


Yes.
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Thanks everyone, hopefully that's the last of my problems on this topic.

This topic is closed to new replies.

Advertisement