C++ 变量或字段“generateMonster';宣告无效

C++ 变量或字段“generateMonster';宣告无效,c++,C++,可能重复: 我正在做一个项目,在功能方面遇到了一些问题。我不断得到一个错误,我知道这意味着我从未声明过类型,但我知道我是。所有文件都包含.h和.cpp,因此我没有任何缺少的包含 这就是我调用它的函数-问题是generateMonster int room1(charType& heroObj) { int r; roomType RoomObj; RoomObj.generateMonster(heroObj); cout << "The

可能重复:

我正在做一个项目,在功能方面遇到了一些问题。我不断得到一个错误,我知道这意味着我从未声明过类型,但我知道我是。所有文件都包含.h和.cpp,因此我没有任何缺少的包含

这就是我调用它的函数-问题是generateMonster

int room1(charType& heroObj) {

    int r;
    roomType RoomObj;
    RoomObj.generateMonster(heroObj);

    cout << "There's a hiss as you open this door, and you smell a sour odor, like something rotten or fermented. Inside you see a small room lined with dusty shelves, crates, and barrels. It looks like someone once used this place as a larder, but it has been a long time since anyone came to retrieve food from it." << endl;
    cout << endl << "Room #1:\n 1. Door in the East corner of the North wall.\n 2. Door in the middle of the East wall.\n 3. Door in the east corner of the south wall.\n 4. Door in the West corner of the South wall.\n" << endl;
    doIt();
    cin >> r;
    if (!cin.good())
       cout << "That is not a valid option.  Please try again.";
       cin.clear();
       cin.ignore(100, '\n');

    system("cls");

    switch(r) {
              case 1:
                   genDoor();
                   hallway1(heroObj);
                   break;
              case 2:
                   genDoor();
                   hallway4(heroObj);
                   break;
              case 3:
                   genDoor();
                   hallway3(heroObj);
                   break;
              case 4:
                   genDoor();
                   hallway2(heroObj);
                   break;
    }

}

而我的函数作为一个整体-

基于,问题似乎是编译器不知道
ChartType
是在哪里声明的
generateMonster(ChartType&)
。也许
#在
类roomType
之前包含“charType.h”

也许您应该复制/粘贴准确的错误消息。我看到了,但我声明的类型不是std:,而是一个类。@VernBurton问题是编译器不知道您所说的类型。不提供名称空间只是导致此错误消息的一种方式。在您的情况下,我认为可能是缺少了
#include
(请参见我的答案)。包含了.h文件,但问题在于它们的顺序。当然,这是很简单的。@VernBurton为了使这个问题不可能发生,你应该在你的
roomType.h
中加入“charType.h”。当您多次包含一个文件时,您还需要使用来防止错误。谢谢。这是我第一次尝试使用编译语言,到目前为止我没有什么可抱怨的。
class roomType
    {
    public:
     roomType();
     void generateMonster(charType& heroObj);
     void generateTreasure();

    private:
     int gold;
     int potion;
     int keys;
    };