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. Question about classes in C++

Question about classes in C++

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 6 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.
  • A Offline
    A Offline
    akirilov
    wrote on last edited by
    #1

    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

    C S C A R 5 Replies Last reply
    0
    • A akirilov

      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

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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++

      1 Reply Last reply
      0
      • A akirilov

        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

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • A akirilov

          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

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A akirilov

            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

            A Offline
            A Offline
            akirilov
            wrote on last edited by
            #5

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

            C S 2 Replies Last reply
            0
            • A akirilov

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

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              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]

              A 1 Reply Last reply
              0
              • C CPallini

                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]

                A Offline
                A Offline
                akirilov
                wrote on last edited by
                #7

                :laugh: Well I tried A.Paint() before I posted here ;) so, A::Paint() is working fine.

                1 Reply Last reply
                0
                • A akirilov

                  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

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

                  Along with other answers, see the __super[^] keyword. You could call a parent class function by __super::FuncName() [EDIT] OK, I just read you already are going to settle on this keyword. [/EDIT]

                  It is a crappy thing, but it's life -^ Carlo Pallini

                  1 Reply Last reply
                  0
                  • A akirilov

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

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #9

                    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

                    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