Re: Newbie static class member question [C++]

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 04/17/04


Date: Sat, 17 Apr 2004 07:01:17 +0100

In message <sf8180p8upsud6sb44rb0bv5ckdetcfv8h@4ax.com>, Leor Zolman
<leor@bdsoft.com> writes
>Actually it's "class definition". In C++, a class declaration looks like
>this:
>
> class Foo;
>
>and allows subsequent declarations to refer to Foo in certain contexts
>(such as defining a pointer or reference to Foo) but not others (such as
>defining an object of type Foo). The above results in Foo being an
>"incomplete type", to be completed after the compiler sees the class
>definition. I know, the terms are infuriatingly inconsistent and
>overloaded. That's life with C++.

Well there are a lot of little inconsistencies in C++ but I do not think
this is one of them. A declaration introduces a name with information
about how it can be used. That information is type information so:

int i;
there is a name 'i' which designates an int

int foo(double);

there is a name 'foo' which designates a function which uses a single
value of type double and returns a value of int type.

class mytype;

there is a name 'mytype' that designates a user defined class type.

In some contexts a declaration is also a definition. A definition
provides a point where all the information necessary to use an entity
has been provided.

The thing that confuses some people (and most authors:() is that a class
definition consists of the declarations of its members. If you think
about it that is all that is needed to use a class object. However those
declarations just introduce the names of the parts of the class. At that
inner level we have names that still need definitions. We conventionally
call the set of definitons of the members of a class 'its
implementation. This has got generalised into optionally referring to a
function definition as its 'implementation'owever C++ is always clear as
to whether a statement is just a declaration or is also a definition. C
isn't because it has something called a 'tentative definition' which
effectively means that it is a definition until something better comes
along. C++ does not allow that, something is either unambiguously a
definition or it is just a declaration.

-- 
Francis Glassborow      ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


Relevant Pages

  • Re: undefined reference to "..."
    ... compiler has a declaration of the function, ... extern int foo(int); ... Declarations appearing in the header files have ...
    (comp.lang.c)
  • Re: Strange function use
    ... int a, b, foo; ... int a, b, foo(int); ... the function prototype "foo" expects an integer argument ... foooccurs inside a declaration. ...
    (comp.lang.c)
  • Re: Strange function use
    ... int a, b, foo; ... int a, b, foo(int); ... foooccurs inside a declaration. ... function prototype declaration. ...
    (comp.lang.c)
  • Re: Newbie static class member question [C++]
    ... >>(such as defining a pointer or reference to Foo) but not others (such as ... >there is a name 'i' which designates an int ... >In some contexts a declaration is also a definition. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Question about multiple files
    ... No. extern just means: The actual definition is somewhere else. ... the compiler can differentiate between declaration and definition just ... > declaration it finds and in this way can I write code expecting it to be ... When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)