seprate compilation for classes

Discussion in 'C++' started by katyusha, Apr 16, 2008.

  1. katyusha

    katyusha Guest

    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 )
     
    katyusha, Apr 16, 2008
    #1
    1. Advertising

  2. katyusha

    asterisc Guest

    On Apr 16, 2:20 pm, 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 )


    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.
     
    asterisc, Apr 16, 2008
    #2
    1. Advertising

  3. 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.
     
    Juha Nieminen, Apr 16, 2008
    #3
  4. On Apr 16, 7:20 am, 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 )


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

    http://www.eventhelix.com/RealTimeMantra/HeaderFileIncludePatterns.htm

    --
    EventStudio 4.0 - http://www.Eventhelix.com/Eventstudio/
    Sequence diagram based systems engineering tool
     
    EventHelix.com, Apr 17, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Classes within classes

    David, Jul 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,966
    David
    Jul 22, 2005
  2. lonelyplanet999
    Replies:
    1
    Views:
    2,249
    VisionSet
    Nov 13, 2003
  3. Replies:
    6
    Views:
    371
    red floyd
    Sep 6, 2006
  4. C__chp
    Replies:
    4
    Views:
    520
    Puppet_Sock
    Feb 15, 2008
  5. Robhy B.
    Replies:
    3
    Views:
    115
    zuerrong
    Dec 9, 2010
Loading...

Share This Page