0

Don't know what I'm getting wrong. I'm new to inheritance. Including all errors I got:

21  7   D:\My C++ programs\inheritance.cpp  [Error] redefinition of 'class Sharad'
5   7   D:\My C++ programs\inheritance.cpp  [Error] previous definition of 'class Sharad'
D:\My C++ programs\inheritance.cpp  In function 'int main()':
27  2   D:\My C++ programs\inheritance.cpp  [Error] 'Sourabh' was not declared in this scope
28  2   D:\My C++ programs\inheritance.cpp  [Error] 's1' was not declared in this scope

Code:

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class Sharad{
string a,b,c,d,e;
public:
    void getinfo()       
    {
        cout<<"Enter your Dad's full name: "<<endl;
        cin>>a;
        cout<<"Enter your full name: "<<endl;
        cin>>b;
    }
    void showinfo()   //Error no. 2-5   7   D:\My C++ programs\inheritance.cpp  [Error] previous definition of 'class Sharad'
    {
        cout<<"Your dad's name is: "<<a<<endl;
        cout<<"Your name is: "<<b<<endl;
    }   
};
  class Sharad : public Sourabh //error no. 3- D:\My C++ programs\inheritance.cpp   In function 'int main()':27 2   D:\My C++ programs\inheritance.cpp  [Error] 'Sourabh' was not declared in this scope
 {

 }; 
 int main()       //error 4- 28 2   D:\My C++ programs\inheritance.cpp  [Error] 's1' was not declared in this scope

  {
 Sourabh s1;
  s1.getinfo();
  s1.showinfo();
  getch();
  return 0;
}
halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

2
class Sharad : public Sourabh

This is the wrong way around. Sourabh is the new class that inherits from Sharad:

class Sourabh : public Sharad
nvoigt
  • 75,013
  • 26
  • 93
  • 142