Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts

    C++ equivalent of Java's super.method() ?

    What is the C++ equivalent of accessing superclass methods that are overwritten by a subclass?

    Java code:
    Code:
    public class A {
       public void println() {
          System.out.println("from A");
    }
    
    public class B extends A {
       public void println() {
          super.println();
          System.out.println("from B");
    }
    How is this done in C++?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Maybe the following. I don't know a whole lot about inheritance in C++.
    Code:
    A::println()

  • #3
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    A quick example:
    Code:
    class GameRoot {
    ...
    }
    GameRoot is a subclass of SolitaireBase
    Code:
    class SolitaireBase : public GameRoot {
    ...
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •