super

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ashish_CPP
    New Member
    • Jul 2006
    • 35

    #1

    super

    Hi,
    A keyword "super" is used in C++ in classes. It is said that it is used for accessing base class from the derived class. But I am unable to understand its real purpose. Accessing just a base class doesn't serve the purpose of keeping a extra keyword. Can anyone explain it elaborately.

    Thanks in advance.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    This sentence

    Accessing just a base class doesn't serve the purpose of keeping a extra keyword.
    Doesn't make sense.

    However there is no "super" keyword in C++ are you thinking of Java? If you want to access a base class from a derived class you just use the base class as a prefix

    Code:
    class BaseClass
    {
    public:
        void PrintMe();
    
    }
    
    class DerivedClass : public BaseClass
    {
    public:
        void PrintMe();
    
    }
    
    void DerivedClass::PrintMe()
    {
        cout << "In derived class" << endl;
        BaseClass::PrintMe();
    }

    Comment

    • Ashish_CPP
      New Member
      • Jul 2006
      • 35

      #3
      No no, the keyword "super" is there in C++. I am giving a link of MSDN where you can find the notes for it, but its only briefly given. I want an elaborate explanation.

      http://msdn.microsoft.com/library/de.../key_s-z_1.asp

      It is said that we can access any member of any base class through this keyword, but that can be done with the usual procedure of class also, then what is the purpose of this keyword.

      Please go through the above link, "super" is there in C++.

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        It is a Microsoft specific extension of C++, i.e. not standard C++, it is clearly not required so it is not clear why they chose to add it (perhaps you better phone Bill Gates :D).

        I guess they have put it in to aid people familiar with Java, however I would avoid using it if I where you.

        Comment

        • Ashish_CPP
          New Member
          • Jul 2006
          • 35

          #5
          Originally posted by Banfa
          It is a Microsoft specific extension of C++, i.e. not standard C++, it is clearly not required so it is not clear why they chose to add it (perhaps you better phone Bill Gates :D).

          I guess they have put it in to aid people familiar with Java, however I would avoid using it if I where you.

          Oh so "super" is a microsoft specific keyword for C++, since it was used in our project which is in microsoft language thatz why I was unable to understand it. Anyway I dont have Bill gates phone number(Ha ha ha...).
          Thanks a lot.

          Comment

          Working...