#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
class Child{
public:
string setName(string name){name = name;}
string getName(){return name;}
private:
string name;
};
class Parent : Child{
public:
string setPName(string parent){pName = parent;}
string getParent(){return pName;}
Child kid;
private:
string pName;
};
int main(){
Parent dad;
dad.kid.setName("Sandy");
dad.setPName("David");
cout << "The dads childs name is " << dad.kid.getName();
cout << "The dads name is " << dad.getParent();
return 0;
}
I am getting a Segmentation 11 Fault in my console when I run, However it is building just fine. Any reason for this? I'd like some help pointing it out so I don't make the same simple mistake! Thanks guys. Just messing around with inheritance for nearly the first time