seprate compilation for classes

K

katyusha

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

asterisc

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

Juha Nieminen

katyusha said:
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.
 
E

EventHelix.com

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/RealTimeMantra/HeaderFileIncludePatterns.htm
 

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
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top