Re: #include question
From: Dan Moos (dan.moos_at_verizon.net)
Date: 03/01/04
- Next message: Greg Comeau: "Re: Number to String"
- Previous message: Francis Glassborow: "Re: C++ problem with sorting array"
- In reply to: Francis Glassborow: "Re: #include question"
- Next in thread: Chris \( Val \): "Re: #include question"
- Reply: Chris \( Val \): "Re: #include question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 01 Mar 2004 20:16:43 GMT
"Francis Glassborow" <francis@robinton.demon.co.uk> wrote in message
news:mc6QziE0dxQAFwOs@robinton.demon.co.uk...
> In message <ljv0c.18979$6K.11191@nwrddc02.gnilink.net>, Dan Moos
> <dan.moos@verizon.net> writes
> >No that is what I meant, and you answered my question.
> >
> >Lets see if I got this right...
> >
> >The definition of a class or template tells the compiler what to do when
an
> >object is created. After the compiler has created all the objects of a
> >certain class, the class definition is no longer useful, SO it doesn't
end
> >up in the final executable, thus, you really aren't adding redundant code
to
> >the executable, in fact you aren't even adding the initial definition.
The
> >definition is for the COMPILER, not the executable.
> >
> >Am I on the right track?
> >
> >
> Yes, but not quite at the destination.
>
> Definitions of variables and functions tell the compiler what to do when
> the name they declare is used.
>
> Definitions of classes and structs tell the compiler enough about
> storage requirements + the available functionality so that it your
> source code can use objects of the relevant type.
>
> However the class/struct also usually requires an implementation. That
> consists of the definitions of the functions that were declared in the
> definition of the class/struct.
>
> C++ provides an option for some (or even all) the implementation to be
> provided within the class definition and requires that there shall be
> some latter 'magic' that handles possible redefinition errors when more
> than a single TU has opted to provide actual callable versions rather
> than inline the code.
>
> Summary:
>
> By default a variable is defined (which includes declaration) unless it
> is part of a class definition where it will be declared and it is the
> job of the ctor to define it. Other variables can only be declared by
> use of the 'extern' keyword that effectively switches off the default
> behaviour.
>
> A function is usually declared in a header file. Its implementation is
> called a definition and is usually placed in a separate .cpp file. If
> the linker sees the results of more than one definition of a function
> then it will issue a redefinition error unless:
>
> a) the function was declared as inline either implicitly because the
> definition was in a class definition or explicitly by use of the inline
> keyword.
>
> b) The multiple definitions occur in library files being used to resolve
> external definitions. In this case the first definition fund will be
> used and the problem will be treated as solved. Note this can result in
> some very subtle errors but in practice such problems are rare.
>
> A class/struct can be declared (i.e. only the name is given) which is
> enough for use of references and pointers to that type. It is normally
> defined (in a header file) and, for use it need to be implemented
> (normally in a separate TU)
>
> enums can only de simultaneously defined and declared as C++ does not
> provide a mechanism for pure declaration of an enum (there are good
> reasons but let us not go there today)
>
> Typedefs are effectively pure declarations because they introduce new
> names for existing (possibly compound) types.
>
> I think that covers most issues until we start looking at generic
> facilities provided via templates.
right on, that really helps.
Thanks againg folks
- Next message: Greg Comeau: "Re: Number to String"
- Previous message: Francis Glassborow: "Re: C++ problem with sorting array"
- In reply to: Francis Glassborow: "Re: #include question"
- Next in thread: Chris \( Val \): "Re: #include question"
- Reply: Chris \( Val \): "Re: #include question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|