不知道我错了什么。我是继承人的新手。包括我得到的所有错误:
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
代码:
#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;
}