Connecting Tech Pros Worldwide Help | Site Map

include problem

ScOe
Guest
 
Posts: n/a
#1: Jul 22 '05
I have class TZone which needs to contain array of TMonster class

#include "Monsters.h"
....
std::vector <TMonster> Monsters;

this declaration throw compiler error Undefined symbol TMonster.
next declaration in this header is container TItems. This one compile ok.

What could be the problem. I thought of cross linkage problem, but i
couldn't find " the source of problems"
Any suggestions ?


Howard
Guest
 
Posts: n/a
#2: Jul 22 '05

re: include problem



"ScOe" <cbinders@hotmail.com> wrote in message
news:cnl61f$6v0$1@bagan.srce.hr...[color=blue]
>I have class TZone which needs to contain array of TMonster class
>
> #include "Monsters.h"
> ...
> std::vector <TMonster> Monsters;
>
> this declaration throw compiler error Undefined symbol TMonster.
> next declaration in this header is container TItems. This one compile ok.
>
> What could be the problem. I thought of cross linkage problem, but i
> couldn't find " the source of problems"
> Any suggestions ?
>
>[/color]

I'm assuming that Monsters.h declares the TMonster class? Does it? If it
declares a class called Monsters, and you want to create a vector called
TMonster that holds instances of that, then your declaration is backwards.
It would need to be:

std::vector<Monsters> TMonster;

Otherwise...

Is the TMonster class in a namespace? Do you have a Monsters.cpp
(implementation) file that goes with it? If so, does *it* compile ok? If
you have an error in that header file, then you won't be able to see
declarations from it in a dependant source file. If those ideas don't help,
then we'd need to see more code, especially the Monsters.h contents. Also
any other compiler errors or warnings, since those might point to where the
"real" problem lies.

-Howard



Jay Nabonne
Guest
 
Posts: n/a
#3: Jul 22 '05

re: include problem


On Fri, 19 Nov 2004 17:12:07 +0100, ScOe wrote:
[color=blue]
> I have class TZone which needs to contain array of TMonster class
>
> #include "Monsters.h"
> ...
> std::vector <TMonster> Monsters;
>
> this declaration throw compiler error Undefined symbol TMonster.
> next declaration in this header is container TItems. This one compile ok.
>
> What could be the problem. I thought of cross linkage problem, but i
> couldn't find " the source of problems"
> Any suggestions ?[/color]

You can have this problem if you have two header files including each
other (e.g. a.h includes b.h and b.h includes a.h), each having
include guards.

How to resolve a situation like that depends on the declarations and how
they're being used.

- Jay
Default User
Guest
 
Posts: n/a
#4: Jul 22 '05

re: include problem


ScOe wrote:
[color=blue]
> I have class TZone which needs to contain array of TMonster class
>
> #include "Monsters.h"
> ...
> std::vector <TMonster> Monsters;
>
> this declaration throw compiler error Undefined symbol TMonster.
> next declaration in this header is container TItems. This one compile
> ok.
>
> What could be the problem. I thought of cross linkage problem, but i
> couldn't find " the source of problems"
> Any suggestions ?[/color]

Yeah, don't leave out big chunks of your code when you ask for help. We
end up guessing about the missing parts.

Post a complete, minimal program that demonstrates the problem.




Brian
ScOe
Guest
 
Posts: n/a
#5: Jul 22 '05

re: include problem


[color=blue]
>
> You can have this problem if you have two header files including each
> other (e.g. a.h includes b.h and b.h includes a.h), each having
> include guards.
>[/color]
This could be the problem ...
[color=blue]
> How to resolve a situation like that depends on the declarations and how
> they're being used.
>[/color]
WorldClass.h
//---------------------------------------
#include "GlobalDefs.h"
#include "RoomClass.h"
#include "Monsters.h"
class TWorld
{
private:
TVecArray <TZone> FZones;
public:
AnsiString FWorldDirectory;
AnsiString FItemsDirectory;
AnsiString FMonstersDirectory;
TWorld ();
void LoadZones ();
void XMLtoClass (String FFileName);
bool LoadFromFile (std::vector<AnsiString> *sLines, String FFileName);
TRoom GetRoom (int ZoneNumber, int RoomNumber);
TZone *GetZone (int ZoneNumber);
};

class TZone
{
public:
....
std::vector <TMonster> ZoneMobs;
....
TMonster *GetMob (int MobID);
....
TWorld *Parent;
void LoadMobs ();
};



Monsters.h
//--------------------------------------------------------------------------
-
#include "GlobalDefs.h"
#include "Items.h"
#include "WorldClass.h"
class TMonster
{
public:
....
std::vector <TItem> Inventory;
....
TWorld *MyWorld;
__fastcall TMonster ();
__fastcall TMonster (TWorld *World);
__fastcall TMonster (TWorld *World, sStats *pStats, sEquipment
*pEquipment);
....
};
//--------------------------------------------------------------------------
-
[color=blue]
> - Jay[/color]


Closed Thread


Similar C / C++ bytes