我在C 中写了一个简单的继承程序,但是我有很多错误
I am writing a simple inheritance program in C++, but I got many errors
不知道我出了什么问题。我是继承的新手。包括我遇到的所有错误:
21 7 D:My C++ programsinheritance.cpp [Error] redefinition of 'class Sharad'
5 7 D:My C++ programsinheritance.cpp [Error] previous definition of 'class Sharad'
D:My C++ programsinheritance.cpp In function 'int main()':
27 2 D:My C++ programsinheritance.cpp [Error] 'Sourabh' was not declared in this scope
28 2 D:My C++ programsinheritance.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++ programsinheritance.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++ programsinheritance.cpp In function 'int main()':27 2 D:My C++ programsinheritance.cpp [Error] 'Sourabh' was not declared in this scope
{
};
int main() //error 4- 28 2 D:My C++ programsinheritance.cpp [Error] 's1' was not declared in this scope
{
Sourabh s1;
s1.getinfo();
s1.showinfo();
getch();
return 0;
}
class Sharad : public Sourabh
这是错误的方式。Sourabh
是从Sharad
继承的新类:
class Sourabh : public Sharad
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 继承函数的重载解析
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 为什么这个混合继承程序给出错误的输出?
- 消息分析程序继承的替代方法
- 多级继承程序代码的输出
- 混淆了具有虚拟继承的程序输出
- 我在C 中写了一个简单的继承程序,但是我有很多错误
- 从应用程序启动 Linux 服务时避免套接字继承C++
- 在程序启动时关闭所有继承的 fds
- 信号处理程序与虚拟函数和继承(事件处理)
- opencv函数的继承是否使我的程序变得更好
- 使用 Windows V2 凭据提供程序的钻石继承
- c++中关于带有多个类和头文件的传递程序中的继承、隐私和对象的问题
- 使用虚继承的简单程序汇编输出
- 多重继承和泛型程序
- 对复制构造函数的c++ OOP程序问题?继承
- C++面向对象程序复制了继承模式
- c++简单程序实现中的继承和虚函数错误