Constructors while inheritance

#include <iostream>
#include <string.h>

using namespace std;

class A
{
public:
  A()
  {
    cout << "A's constructor" << endl;
  }

  A(string s)
  {
    cout <<  "A's " << s << endl;
  }
};

class B : public A
{
public:
  B()
  {
    cout << "B's constructor" << endl;
  }

  B(string s) : A(s)
  {
    cout << "B's " << s << endl;
  }
};

class C : public B
{
public:
  C()
  {
    cout << "C's constructor" << endl;
  }

  C(string s) : B(s)
  {
    cout << "C's " << s << endl;
  }


};

int main(int argc, char const *argv[])
{
  C c("Hello");

  return 0;
}

Comments

Popular posts from this blog

Zeller's Congruence

Property Event-Delegation

Method with variable arguments