class Base{
    Base();
    ~Base();
    void doSomrthing();
}

Class MyCLass : public Base{
    std::string name;
    MyCLass();
    ~MyCLass();
    void init();
}    

MyCLass::MyCLass()
{
    init(); //runtime error occurs with this line
}
void MyCLass::init()
{
    name = "MyClass";
    doSomrthing();
}

I am having a trouble on calling child class' contructor. What is wrong with this?

Edited 3 Years Ago by 9tontruck

Could it be this

Class

Please note the uppercase C

Or could it be the missing semi-colon here

class Base
{
  Base();
  ~Base();
  void doSomrthing();
}

Or here

Class MyCLass : public Base{
std::string name;
MyCLass();
~MyCLass();
void init();
} 

Edited 3 Years Ago by gerard4143

Here's a correction implementing some of the changes mentioned above

#include <iostream>

class Base
{
public:
  Base() {}
  ~Base() {}
  void doSomrthing() {}
};

class MyCLass : public Base
{
  std::string name;
public:
  MyCLass();
  ~MyCLass();
  void init();
};

MyCLass::MyCLass()
{
  init(); //runtime error occurs with this line
}

void MyCLass::init()
{
  name = "MyClass";
  doSomrthing();
}

int main()
{}

The base class' constructor and destructor are private, so an inherited class can't call them. Which is bad.

This question has already been answered. Start a new discussion instead.