C++ equivalent of super

This is a discussion on C++ equivalent of super within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by @nthony Such a change won't affect clients using Bar (who will continue to use the unchanged Bar) ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    Quote Originally Posted by @nthony
    Such a change won't affect clients using Bar (who will continue to use the unchanged Bar) nor clients using Foo if the public interface to Foo remains unchanged.
    It will affect clients using Bar* (or smart_ptr<Bar>) to point to a Foo object, even if BarV2 provides the exact same public interface as Bar, unless BarV2 publicly inherits from Bar.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,620
    Quote Originally Posted by @nthony View Post
    @grumpy
    I meant this by reusable/"resistant to change":
    Code:
    public class Foo extends Bar
    {
        public void draw() { super.draw(); }
    }
    Yes, I knew what you meant.
    Quote Originally Posted by @nthony View Post
    But I've figured out a close approximation using a simple macro:
    Code:
    #define SUPER base
    class Foo : public base {
    ..
    }
    undef SUPER
    Your approach also specifically requires that all member functions of your class are implemented inline with the class declaration.

    The typedef approach I suggested does what you want (with the exception that it is necessary to use "super::draw()" rather than "super.draw()"). That is a syntactic difference, not a functional one. If you insist on Java syntax, then use Java.

    Quote Originally Posted by @nthony View Post
    I agree providing hooks is more to do with creating interfaces (as is templating); however I'd tend to think that interfacing and derivation are separate concepts in OO design. Meaning one shouldn't have to interface to derive. (or rather, how would you derive from an interface in such a model?)
    With that comment, you've shown a fundamental misunderstanding of OO design.

    Interface is a fundamental requirement for derivation: the intent of derivation is that the derived class implements the same interface as the base class, but can provide different implementation of the behaviour required by that interface. Yes, with derivation, it is possible to extend an interface (eg a derived class provides the base class interface, plus more) but the key premise of derivation is still that the derived class supports the base class interface.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows equivalent to linux curl command?
    By elmutt in forum Windows Programming
    Replies: 5
    Last Post: 02-29-2008, 06:16 AM
  2. Pointer equivalent to array notation
    By bekkilyn in forum C Programming
    Replies: 4
    Last Post: 12-06-2006, 08:22 PM
  3. Replies: 10
    Last Post: 08-18-2005, 12:17 AM
  4. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  5. With super powers would you:
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-18-2003, 12:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21