cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/30/21:33:09

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Multiple files (was mispelled)
Date: Mon, 28 Jul 1997 10:15:08 -0700
Organization: Alcyone Systems
Lines: 46
Message-ID: <33DCD39C.7CA44E2B@alcyone.com>
References: <5r978a$9ee$1 AT news DOT bctel DOT net>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Thomas Christensen wrote:

> I am using RHide 1.3.

I think your question is a general C/C++ question.

> I am writing an application and wish to use several files to keep
> things neat. My problem is when I compile the individual files any
> file that uses a class defined in another file gives me an error. If I
> include the file with the class I am including the application will
> compile without an error but when it links I get an error that there
> are multipal definitions of the classes. What do I have to do to tell
> a file about a class defined in another file?

In the header file, you declare the class (e.g., this is my class, and
these are its members and member functions).  In the source file, you
_define_ the class (e.g., okay, here is what these members are and here is
what these member functions do).

This division makes things easy to organize:  If a class requires another
class or another header file, it's just included at the top of the
dependent header file.  Using preprocessing to prevent multiple inclusion
of the same file guarantees that you can do this with impunity:

    // example.hh

    #ifndef EXAMPLE_HH
    #define EXAMPLE_HH

        // actual contents of header

    #endif

If classes use one another (e.g., class A contains an element of class B)
then things get more complicated and you'll have to combine the two
classes into one header or use opaque pointers (e.g., class A contains a
pointer to class B, so the header doesn't need to know anything about the
internals of class B at header compile time).

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
   "Love is not love which alters / when it alternation finds."
                                 / William Shakespeare, _Sonnets_, 116

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019