Help with OOP
-
Hello everyone! I'm designing a OOP-based system in C++, and I'm having a little problem. Say I have this:
class Class1 { virtual void Draw(Image *a_pImage); }; class Class2 : public Class1 { virtual void Draw(Image *a_pImage); };
Class1::Draw takes care of ugly low-level stuff, and that's a lot of code. How can Class2::Draw call Class1::Draw so that I don't have to copy-paste all of the code in Class2? In C#, for example, you used base.Draw, but base doesn't exist in C++... Thanks!
Windows Calculator told me I will die at 28. :(
-
Hello everyone! I'm designing a OOP-based system in C++, and I'm having a little problem. Say I have this:
class Class1 { virtual void Draw(Image *a_pImage); }; class Class2 : public Class1 { virtual void Draw(Image *a_pImage); };
Class1::Draw takes care of ugly low-level stuff, and that's a lot of code. How can Class2::Draw call Class1::Draw so that I don't have to copy-paste all of the code in Class2? In C#, for example, you used base.Draw, but base doesn't exist in C++... Thanks!
Windows Calculator told me I will die at 28. :(
void Class2::Draw(Image *a_pImage) { // add extra code for Class2 draw Class1::Draw(a_pImage); // add extra code for Class2 draw }
modified on Friday, February 15, 2008 12:15 AM
-
void Class2::Draw(Image *a_pImage) { // add extra code for Class2 draw Class1::Draw(a_pImage); // add extra code for Class2 draw }
modified on Friday, February 15, 2008 12:15 AM
Huh? That easy? I was expecting an extremely long message explaining how to delicately trick C++ into doing what I wanted... Thanks , Rajkumar!
Windows Calculator told me I will die at 28. :(
-
Huh? That easy? I was expecting an extremely long message explaining how to delicately trick C++ into doing what I wanted... Thanks , Rajkumar!
Windows Calculator told me I will die at 28. :(
Lord Kixdemp wrote:
Huh? That easy?
"One of the difficulties people have with object-oriented design is that it's too simple to get from the beginning to the end. A mind trained to look for complex solutions is often stumped by this simplicity at first" - Bruce Eckel.
-
Lord Kixdemp wrote:
Huh? That easy?
"One of the difficulties people have with object-oriented design is that it's too simple to get from the beginning to the end. A mind trained to look for complex solutions is often stumped by this simplicity at first" - Bruce Eckel.
nice quote :)
-
Hello everyone! I'm designing a OOP-based system in C++, and I'm having a little problem. Say I have this:
class Class1 { virtual void Draw(Image *a_pImage); }; class Class2 : public Class1 { virtual void Draw(Image *a_pImage); };
Class1::Draw takes care of ugly low-level stuff, and that's a lot of code. How can Class2::Draw call Class1::Draw so that I don't have to copy-paste all of the code in Class2? In C#, for example, you used base.Draw, but base doesn't exist in C++... Thanks!
Windows Calculator told me I will die at 28. :(
Lord Kixdemp wrote:
virtual void Draw(Image *a_pImage);
Class2::Draw()
is virtual by default. Thevirtual
keyword is unnecessary."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne