0

Possible Duplicate:
Is there a way to call an object's base class method that's overriden? (C++)

First question is calling super() constructor in java same as initializing the super class constructor first in c++ like.

sub() : super(){}


is there a way to call super class method in c++ like in java

ex.

public sub(){
super.someMethod(); 

}

Community
  • 1
  • 1
user1348869
  • 103
  • 1
  • 4
  • possible duplicate of [C++: How to call a parent class function from derived class function?](http://stackoverflow.com/q/357307/), [Is there a way to call an object's base class method that's overriden? (C++)](http://stackoverflow.com/q/1619769/) – outis Apr 22 '12 at 00:05

1 Answers1

6

To call the base constructor of a class, you call it as BaseClassName(args). For example:

class A
{
public:
    A() { }
    virtual void Foo() { std::cout << "A's foo" << std::endl; }
};

class B : public A
{
public:
    B() : A() { }
    void Foo();
};

To call the base class version of a method, you do BaseClassName::MethodName:

void B::Foo()
{
    std::cout << "B's foo" << std::endl;
    A::Foo();
}
Mike Bailey
  • 12,479
  • 14
  • 66
  • 123