0

Possible Duplicate:
variable or field declared void

I am working on a project getting some issues with a function. I keep getting a error which I know means that I never declared a type, but I know I am. All files have .h and .cpp included, so I don't have any missing includes.

this is the function I call it with - the issue is the 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;
    }

}

my prototype

class roomType
    {
    public:
     roomType();
     void generateMonster(charType& heroObj);
     void generateTreasure();

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

and my function as a whole - http://pastie.org/4799752

Community
  • 1
  • 1
Vern Burton
  • 3,215
  • 1
  • 18
  • 31
  • Perhaps you should copy/paste the exact error message. – CrazyCasta Sep 25 '12 at 21:05
  • I saw that, but my declared type isn't a member of std:, but a class. – Vern Burton Sep 25 '12 at 21:08
  • @VernBurton The problem is that the compiler doesn't know what type you're talking about. Not giving the namespace is just one way of causing this error message. In your case, I think it's likely a missing `#include` (see my answer). – Brendan Long Sep 25 '12 at 21:11

1 Answers1

2

Based on this question, the problem seems to be that the compiler doesn't know what charType is where generateMonster(charType&) is declared. Maybe #include "charType.h" before class roomType?

Community
  • 1
  • 1
Brendan Long
  • 53,280
  • 21
  • 146
  • 188
  • The .h files were included but it was the order that they were that was the issue. Of course, it was something so simple. – Vern Burton Sep 25 '12 at 21:15
  • 2
    @VernBurton To make this problem not possible, you should do the `#include "charType.h"` in your `roomType.h`. You'll also want to use [include guards](http://stackoverflow.com/a/8020211/212555) to prevent errors when you include a file more than once. – Brendan Long Sep 25 '12 at 21:19
  • Thanks. This has been my first attempt with a compiled language, and so far I can't complain. – Vern Burton Sep 25 '12 at 21:27