0
잘못된 내용을 모릅니다. 나는 상속을 처음 받았다. 내가 가진 모든 오류를 포함 :C++에서 간단한 상속 프로그램을 작성하고 있지만 많은 오류가 있습니다.
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;
}
항상이, 항상 * 항상 * 당신이 얻을 오류를 포함 * 귀하의 질문 * 지역 :
Sourabh
는Sharad
에서 상속 새로운 클래스입니다. 텍스트 및 축 어적으로. –'class Sharad : public Sourabh'가 틀린 길로 보인다 -'클래스 Sourabh : public Sharad'(당신이 정의한 첫 번째 클래스는'Sharad' 이래로)를 원합니다. – UnholySheep
['using namespace std;'는 나쁜 것입니다 연습] (https://stackoverflow.com/q/1452721/2176813)을 사용하지 마십시오. – tambre