Question about classes in C++
-
Hi guys, I have 2 classes:
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint() {...}
}Is it possible and what I have to do, so in B.Paint to invoke A.Paint and then some other code
akirilov wrote:
so in B.Paint to invoke A.Paint and then some other code
Yes:
void B::Paint()
{
A::Paint();
// Other stuff here...
}Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Hi guys, I have 2 classes:
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint() {...}
}Is it possible and what I have to do, so in B.Paint to invoke A.Paint and then some other code
akirilov wrote:
in B.Paint to invoke A.Paint and then some other code
Implement
B::Paint
like this:void B::Paint()
{
A::Paint();
// Do some B specific stuff.
}Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi guys, I have 2 classes:
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint() {...}
}Is it possible and what I have to do, so in B.Paint to invoke A.Paint and then some other code
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint()
{
A::Paint();
...
}
}You can also use __super (if available) like:
class B: public A{
virtual void Paint()
{
__super::Paint();
...
}
}> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <
-
Hi guys, I have 2 classes:
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint() {...}
}Is it possible and what I have to do, so in B.Paint to invoke A.Paint and then some other code
-
Thank you guys, the answer of all of you was very helpful. I tried with A.Paint(), but it didn't work. I'm going to use __super, thus It will not depend of the base class name. THANK YOU, again!!!
akirilov wrote:
I tried with A.Paint(), but it didn't work.
Possibly because they suggested
A::Paint()
instead. :rolleyes:If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
akirilov wrote:
I tried with A.Paint(), but it didn't work.
Possibly because they suggested
A::Paint()
instead. :rolleyes:If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi guys, I have 2 classes:
class A{
virtual void Paint() {...}
}class B: public A{
virtual void Paint() {...}
}Is it possible and what I have to do, so in B.Paint to invoke A.Paint and then some other code
-
Thank you guys, the answer of all of you was very helpful. I tried with A.Paint(), but it didn't work. I'm going to use __super, thus It will not depend of the base class name. THANK YOU, again!!!
akirilov wrote:
I'm going to use __super, thus It will not depend of the base class name.
But it does tie you to Microsoft's compiler...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p