Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   is there a way to tell the compiler that an object exists in adifferent translation unit? (http://www.velocityreviews.com/forums/t554378-is-there-a-way-to-tell-the-compiler-that-an-object-exists-in-adifferent-translation-unit.html)

aaragon 11-22-2007 06:04 PM

is there a way to tell the compiler that an object exists in adifferent translation unit?
 
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< NodeManagerImpl<NodeBase, std::string >
> 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.



Victor Bazarov 11-22-2007 06:47 PM

Re: is there a way to tell the compiler that an object exists in a different translation unit?
 
aaragon wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask



Tomás Ó hÉilidhe 11-22-2007 06:59 PM

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

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



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;

--
Tomás Ó hÉilidhe

James Kanze 11-23-2007 10:45 AM

Re: is there a way to tell the compiler that an object exists in adifferent translation unit?
 
On Nov 22, 7:04 pm, aaragon <alejandro.ara...@gmail.com> wrote:
> 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 >


> > NodeManager;


> 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).

--
James Kanze (GABI Software) email:james.kanze@gmail.com
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

aaragon 11-26-2007 03:35 AM

Re: is there a way to tell the compiler that an object exists in adifferent translation unit?
 
On Nov 23, 4:45 am, James Kanze <james.ka...@gmail.com> wrote:
> On Nov 22, 7:04 pm, aaragon <alejandro.ara...@gmail.com> wrote:
>
> > 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 >
> > > NodeManager;

> > 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).
>
> --
> James Kanze (GABI Software) email:james.ka...@gmail.com
> 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.




All times are GMT. The time now is 10:06 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.