[英]C++ Polymorphism does not work as it should in Code::Blocks 17.12
我使用 Code::Blocks 学习了 C++。 但是,编译器在 Daughter.h 文件的第 6 行中给了我一个错误,当我尝试实现继承时,它说"error: expected-class name before '{' token"
。 这让我更加困惑,因为我在本教程中使用 Code::Blocks 和编译器观看的教程没有给出任何错误,实际上它运行良好。 在这一点上,我有点沮丧。 有人知道如何使它工作吗? 这是我的所有文件:
主程序
//main.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;
int main()
{
Mother jelo;
jelo.sayname();
Daughter tina;
tina.sayname();
}
妈妈.h
//Mother.h
#ifndef MOTHER_H
#define MOTHER_H
class Mother
{
public:
Mother();
void sayname();
};
#endif // MOTHER_H
妈妈.cpp
//Mother.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;
Mother::Mother()
{
}
void Mother::sayname() {
cout << "I am Roberts" << endl;
}
女儿.h
//Daughter.h
#ifndef DAUGHTER_H
#define DAUGHTER_H
class Daughter: public Mother
{
public:
Daughter();
};
#endif // DAUGHTER_H
女儿.cpp
//Daughter.cpp
#include "Daughter.h"
#include "Mother.h"
#include <iostream>
using namespace std;
Daughter::Daughter()
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.