Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > seprate compilation for classes

Reply
Thread Tools

seprate compilation for classes

 
 
katyusha
Guest
Posts: n/a
 
      04-16-2008
Is it possible to seperately compile two classes (suppose class A and
class B ) , and use class A
in class B .I wish to compile two classes class A in A.c and A.hh and
class B in B.c and B.hh , and then use one class in another , by
combining them during link time .(gcc -c A.o B.o -o output )
 
Reply With Quote
 
 
 
 
asterisc
Guest
Posts: n/a
 
      04-16-2008
On Apr 16, 2:20 pm, katyusha <(E-Mail Removed)> wrote:
> Is it possible to seperately compile two classes (suppose class A and
> class B ) , and use class A
> in class B .I wish to compile two classes class A in A.c and A.hh and
> class B in B.c and B.hh , and then use one class in another , by
> combining them during link time .(gcc -c A.o B.o -o output )


In order to use class B in class A, class A MUST see class B's
declaration.
If it use only as a reference or pointer and never dereferentiate it,
you can do a forward declaration, like having "class A;" in B.h.
If you want more than that, like using A's members in B, then you have
to include "A.h" in B.h in order to allow B see A's full declaration.
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      04-16-2008
katyusha wrote:
> Is it possible to seperately compile two classes (suppose class A and
> class B ) , and use class A
> in class B .I wish to compile two classes class A in A.c and A.hh and
> class B in B.c and B.hh , and then use one class in another , by
> combining them during link time .(gcc -c A.o B.o -o output )


Just #include "A.hh" in B.hh and use A in B.

Btw, I think it's a bad idea to name your source files with ".c" if
they are C++ files.

 
Reply With Quote
 
EventHelix.com
Guest
Posts: n/a
 
      04-17-2008
On Apr 16, 7:20*am, katyusha <(E-Mail Removed)> wrote:
> Is it possible to seperately compile two classes (suppose class A and
> class B ) , and use class A
> in class B .I wish to compile two classes class A in A.c and A.hh *and
> class B in B.c and B.hh , and then use one class in another , by
> combining them during link time *.(gcc -c *A.o B.o -o output )


You can use forward declarations to solve this problem. For details
refer to:

http://www.eventhelix.com/RealTimeMa...dePatterns.htm

--
EventStudio 4.0 - http://www.Eventhelix.com/Eventstudio/
Sequence diagram based systems engineering tool
 
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
identifying and removing comments in a seprate ruby file Robhy B. Ruby 3 12-09-2010 01:55 AM
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
Does the gcc compiler have a VC 6.0 C++ compilation mode (interfacing with classes over dll boundary)? bramdoornbos@gmail.com C++ 6 09-06-2006 03:30 PM
Classes within classes David ASP .Net 2 07-22-2005 07:13 PM
How to access inner classes variables & methods from outer classes lonelyplanet999 Java 1 11-13-2003 01:54 PM



Advertisments