Thread: C++ equivalent of super

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Jun 2005
    Quote Originally Posted by @nthony View Post
    I meant this by reusable/"resistant to change":
    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:
    #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.

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-17-2005, 11:17 PM
  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
    Replies: 12
    Last Post: 09-17-2003, 11:27 PM