我正在尝试学习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;
}
Run Code Online (Sandbox Code Playgroud)
mother.cpp:
#include "mother.h"
#include "daughter.h"
#include <iostream>
using namespace std;
mother::mother()
{
//ctor
}
void mother::saywhat() {
cout << "WHAAAAAAT" << endl;
}
Run Code Online (Sandbox Code Playgroud)
mother.h:
#ifndef MOTHER_H
#define MOTHER_H
class mother
{
public:
mother();
void saywhat();
protected:
private:
};
#endif // MOTHER_H
Run Code Online (Sandbox Code Playgroud)
daughter.h:
#ifndef DAUGHTER_H
#define DAUGHTER_H
class daughter: public mother
{
public: …Run Code Online (Sandbox Code Playgroud)