Equivalent of Java's "super" keyword
What I want to do is to be able to access a method that was overridden in a subclass. I could do it in Java but don't know how to do this in C++. It would be something like this:
PHP Code:
class A
{
public:
void method();
};
void A:method()
{
//do something
}
class B : class A
{
public:
method();
};
void B:method();
{
//do what is in class A's method() and then do something else
}
The ". " and its copyright...
When I first studied OOP, and Classes,
they told us to think about "." as a copy right ...
As in the last post,
Quote:
Originally posted by Fordy
Code:
#include <iostream>
using namespace std;
class A{
public:
void Method(void){cout << "Hello from A" << endl;}
};
class B : public A{
public:
void Method(void){
cout << "Hello from B" << endl;}
void CallBoth(void){
Method();
A::Method();//1. Call with base scope
}
};
int main(void){
A myA,*ptrA;
B myB;
myA.Method();
myB.Method();
ptrA = &myB;
ptrA->Method();//2. Call the base function via a base pointer
myB.CallBoth();
return 0;
}
[/B]
After you inheret the public part from class A in B you will be able to access the methods of A class inside the B class.
by writing A.method1(); // And So onn.
I hope you like C++.
Re: The ". " and its copyright...
Quote:
Originally posted by NANO
I hope you like C++.
I think I do like C++ better :D
Thanks all. I've got it all figured out.