首页 > 解决方案 > 编译器错误“class_name”不是类型,“class_name”没有命名类型 C++

问题描述

我不明白为什么我会收到这个错误。当我创建构造函数时,它显示此错误“包”不是类型“包”没有命名类型,如果我删除构造函数,它会编译。

#include <iostream>
#include "bag.h"

using namespace std;

#ifndef PLAYER_H
#define PLAYER_H

class player {
        string name;
        bag *bag;
    public:
        player(string, bag *);
};

player::player(string name = "DEFAULT_NAME", bag *bag = NULL)
{
    this->name = name;
    this->bag = bag;
}

#endif /* PLAYER_H */

Bag 类工作正常并且可以编译,但是一旦我尝试使用 bag 类创建构造函数,我就会收到此错误。

标签: c++classcompiler-errorsinclude-guards

解决方案


推荐阅读