小编Jon*_*nas的帖子

非常基本的继承:错误:'{'标记之前的预期类名

我正在尝试学习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)

c++ inheritance

18
推荐指数
5
解决办法
6万
查看次数

标签 统计

c++ ×1

inheritance ×1