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. base or super-like functionality in C++?

base or super-like functionality in C++?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++javaphpdatabase
5 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.
  • M Offline
    M Offline
    Michael P Scherer
    wrote on last edited by
    #1

    I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:

    class foo {
    public:
    virtual void myMethod() { cout << "this part is in foo" << endl; }
    };

    class bar : public foo {
    public:
    void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
    };

    Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!

    Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)

    F N S 3 Replies Last reply
    0
    • M Michael P Scherer

      I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:

      class foo {
      public:
      virtual void myMethod() { cout << "this part is in foo" << endl; }
      };

      class bar : public foo {
      public:
      void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
      };

      Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!

      Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)

      F Offline
      F Offline
      Fernando A Gomez F
      wrote on last edited by
      #2

      Hi. Just use the base's name:

      class bar : public foo {
      public:
      void myMethod() { **foo::**myMethod(); cout << "\tthis part is in bar" << endl; }
      };

      There's no specific keyword, since C++ allows multiple inheritance and therefore it is not guaranteed that one class has one and only one base class. Regards.

      Stupidity is an International Association - Enrique Jardiel Poncela

      M 1 Reply Last reply
      0
      • F Fernando A Gomez F

        Hi. Just use the base's name:

        class bar : public foo {
        public:
        void myMethod() { **foo::**myMethod(); cout << "\tthis part is in bar" << endl; }
        };

        There's no specific keyword, since C++ allows multiple inheritance and therefore it is not guaranteed that one class has one and only one base class. Regards.

        Stupidity is an International Association - Enrique Jardiel Poncela

        M Offline
        M Offline
        Michael P Scherer
        wrote on last edited by
        #3

        Thanks :) ! Going back to C++ continues to remind me how different it really is from C#

        Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)

        1 Reply Last reply
        0
        • M Michael P Scherer

          I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:

          class foo {
          public:
          virtual void myMethod() { cout << "this part is in foo" << endl; }
          };

          class bar : public foo {
          public:
          void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
          };

          Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!

          Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #4

          Visual C++ provides a non-standard keyword __super[^] that does that. Not that I recommend it :)

          Programming Blog utf8-cpp

          1 Reply Last reply
          0
          • M Michael P Scherer

            I've been working in C# and Java for a while, with only a little experience in using C++, and I'm having a little trouble finding information on if there is anything like base or super in C++. If for example I have this:

            class foo {
            public:
            virtual void myMethod() { cout << "this part is in foo" << endl; }
            };

            class bar : public foo {
            public:
            void myMethod() { base.myMethod(); cout << "\tthis part is in bar" << endl; }
            };

            Such that, base.myMethod() would perform the tasks of myMethod() in the base class, and then it would carry out the new implementation from there; is anything like this possible in C++? thanks!

            Google Profile YouTube Twitter Computer Science Series: Logic (pt1) (part 2) (part 3)

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

            To expand on Fernando's answer - you can't really have a 'base' or 'super' keyword in C++ because a C++ class can inherit from multiple non-abstract bases.

            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