Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with OOP

Help with OOP

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++tutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lord Kixdemp
    wrote on last edited by
    #1

    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. :(

    R D 2 Replies Last reply
    0
    • L Lord Kixdemp

      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. :(

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • R Rajkumar R

        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

        L Offline
        L Offline
        Lord Kixdemp
        wrote on last edited by
        #3

        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. :(

        R 1 Reply Last reply
        0
        • L Lord Kixdemp

          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. :(

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          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.

          R 1 Reply Last reply
          0
          • R Rajesh R Subramanian

            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.

            R Offline
            R Offline
            Rajkumar R
            wrote on last edited by
            #5

            nice quote :)

            1 Reply Last reply
            0
            • L Lord Kixdemp

              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. :(

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Lord Kixdemp wrote:

              virtual void Draw(Image *a_pImage);

              Class2::Draw() is virtual by default. The virtual 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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups