is there a way to tell the compiler that an object exists in adifferent translation unit?

A

aaragon

Hello everyone,

I have this problem that is driving me crazy! I have a typedef for a
singleton object in a file "fileA.h", then I try to use that object in
"fileB.h" and then the compiler says that the object has not been
declared! It doesn't matter what I do, the problem won't go away. I
#include the header file where the typedef is declared, I tried
forward declaration, it just won't go away. The typedef in filaA.h
looks like this:

typedef Loki::SingletonHolder said:
NodeManager;

Then, I try to use this in fileB.h:

...
NodeManager::printNodes();

Any ideas on how to solve this? I can use NodeManager inside fileA.h
and inside main.cxx. I've been compiling only main.cxx so far.

 
V

Victor Bazarov

aaragon said:
I have this problem that is driving me crazy! I have a typedef for a
singleton object in a file "fileA.h", then I try to use that object in
"fileB.h" and then the compiler says [..]

FAQ 5.8

V
 
T

Tomás Ó hÉilidhe

aaragon:


I've only glanced at it, but have you tried playing around with
typename? Something like:

typedef typename Loki::SingletonHolder<
NodeManagerImpl<NodeBase,std::string> > NodeManager;
 
J

James Kanze

I have this problem that is driving me crazy! I have a typedef for a
singleton object in a file "fileA.h", then I try to use that object in
"fileB.h" and then the compiler says that the object has not been
declared! It doesn't matter what I do, the problem won't go away. I
#include the header file where the typedef is declared, I tried
forward declaration, it just won't go away. The typedef in filaA.h
looks like this:
typedef Loki::SingletonHolder< NodeManagerImpl<NodeBase, std::string >

Then, I try to use this in fileB.h:
...
NodeManager::printNodes();

That *looks* like executable code. If so, it probably doesn't
belong in a header.
Any ideas on how to solve this?

NodeManager is a typedef. It must be present in all translation
units which use it. Which means including fileA.h where ever
you use it.

I wonder about one thing. You're at a level where you don't
even know something this fundamental, and you're trying to use
Loki. I'd suggest learning the basics of the language first,
and then tackling Loki. Or Boost, or any other additional
libraries (but Loki is probably more complex than most).
 
A

aaragon

That *looks* like executable code. If so, it probably doesn't
belong in a header.


NodeManager is a typedef. It must be present in all translation
units which use it. Which means including fileA.h where ever
you use it.

I wonder about one thing. You're at a level where you don't
even know something this fundamental, and you're trying to use
Loki. I'd suggest learning the basics of the language first,
and then tackling Loki. Or Boost, or any other additional
libraries (but Loki is probably more complex than most).

--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Is there a way that someone could use Loki without knowing that? Of
course I know it, it was not a problem of including the header file.
If you read the first post I explicitly said "I #include the header
file where the typedef is declared". The problem was that I was not
compiling all .cxx files (dumb me). Well, about Loki, I must confess
that it took me some time to really understand what was going on but I
followed Alexandrescu's advice in the preface and I tried a little
harder. After reading and understanding the book, I must say that
Andrei is a genius. Thank you all for your replies, even if I was not
explicit enough (I'll try harder next time). I hope you all had a
great Thanksgiving break. À tout à l'heure mes amis.

 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top