include problem

S

ScOe

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 ?
 
H

Howard

ScOe said:
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 ?

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
 
J

Jay Nabonne

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 ?

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
 
D

Default User

ScOe said:
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 ?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,976
Members
47,536
Latest member
MistyLough

Latest Threads

Top