LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++ super keyword (https://www.linuxquestions.org/questions/programming-9/c-super-keyword-273766/)

kuna 01-04-2005 12:26 PM

c++ super keyword
 
Is super (http://msdn.microsoft.com/library/de.../key_s-z_1.asp) a microsoft specific keyword? More importantly, if I use it, will gcc recognize it?

deiussum 01-04-2005 01:30 PM

A quick test reveals this:

Code:

#include <iostream>

using namespace std;

class A
{
    public:
        virtual void Test() { cout << "A::Test()" << endl; }
};

class B : public A
{
    public:
        void Test()
        {
            super::Test();
            // This would be the normal way to do this:
            A::Test();
            cout << "B::Test()" << endl;
        }
};

int main()
{
    A* p = new B();

    p->Test();

    delete p;

    return 0;
}

Code:

$ g++ -o blah blah.cpp
blah.cpp: In member function `virtual void B::Test()':
blah.cpp:16: error: `super' undeclared (first use this function)
blah.cpp:16: error: (Each undeclared identifier is reported only once for each
  function it appears in.)
blah.cpp:16: error: parse error before `;' token

So, the answer is no the GNU compiler doesn't support that. It is likely a MS only keyword. Comment out that line, and you get this:

Code:

$ g++ -o blah blah.cpp
$ ./blah
$ ./blah
A::Test()
B::Test()


Proud 01-04-2005 01:43 PM

Have you tried __super?

deiussum 01-04-2005 01:49 PM

Nope, good point. But now I did and get basically the same result.

Code:

blah.cpp: In member function `virtual void B::Test()':
blah.cpp:16: error: `__super' undeclared (first use this function)
blah.cpp:16: error: (Each undeclared identifier is reported only once for each
  function it appears in.)
blah.cpp:16: error: parse error before `;' token

BTW, this is with GCC 3.3.3 for Cygwin...

leonscape 01-04-2005 07:22 PM

This is a MS only keyword. It was rejected from the standard, since it was felt that it added very little, and tended to confuse what was actually being called.

You can acheive a similar result from using typedef's and RTTI. ( Which is probably what the MS compiler is doing. ) You'd think they'd implement the standards betters, before adding there own cruft.


All times are GMT -5. The time now is 11:13 AM.