我正在尝试学习 c++,但在尝试找出继承时偶然发现了一个错误。
编译:daughter.cpp 在 /home/jonas/kodning/testing/daughter.cpp:1 中包含的文件中:/home/jonas/kodning/testing/daughter.h:6:错误:“{”标记之前的预期类名进程以状态 1 终止(0 分钟,0 秒)1 个错误,0 个警告
我的文件:main.cpp:
#include "mother.h"
#include "daughter.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
mother mom;
mom.saywhat();
return 0;
}
母亲.cpp:
#include "mother.h"
#include "daughter.h"
#include <iostream>
using namespace std;
mother::mother()
{
//ctor
}
void mother::saywhat() {
cout << "WHAAAAAAT" << endl;
}
妈妈.h:
#ifndef MOTHER_H
#define MOTHER_H
class mother
{
public:
mother();
void saywhat();
protected:
private:
};
#endif // MOTHER_H
女儿.h:
#ifndef DAUGHTER_H
#define DAUGHTER_H
class daughter: public mother
{
public:
daughter();
protected:
private:
};
#endif // DAUGHTER_H
和女儿.cpp:
#include "daughter.h"
#include "mother.h"
#include <iostream>
using namespace std;
daughter::daughter()
{
//ctor
}
我想做的是让女儿从母类(=saywhat())继承所有公共的东西。我究竟做错了什么?