Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > is there a way to tell the compiler that an object exists in adifferent translation unit?

Reply
Thread Tools

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

 
 
aaragon
Guest
Posts: n/a
 
      11-22-2007
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:rintNodes();

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.


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-22-2007
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


 
Reply With Quote
 
 
 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      11-22-2007
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
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      11-23-2007
On Nov 22, 7:04 pm, aaragon <(E-Mail Removed)> 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:rintNodes();


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:(E-Mail Removed)
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
 
Reply With Quote
 
aaragon
Guest
Posts: n/a
 
      11-26-2007
On Nov 23, 4:45 am, James Kanze <(E-Mail Removed)> wrote:
> On Nov 22, 7:04 pm, aaragon <(E-Mail Removed)> 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:rintNodes();

>
> 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:(E-Mail Removed)
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Trying to cut a person out of a foreground & pasting into adifferent background Eric Prilovich Digital Photography 24 01-03-2013 10:46 PM
Struggling to convert a mysql datetime object to a python string of adifferent format Íßêïò Python 13 02-24-2011 09:53 AM
Is there a way to flush registers and tell the C compiler to refill? Emmanuel Stapf [ES] C Programming 8 03-24-2009 07:41 PM
Declare a Friend function which is a template member function of adifferent class getrakesh@gmail.com C++ 2 02-26-2008 11:32 AM



Advertisments