Topic: Definition, Declaration and forward-declaration
Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: Wed, 11 Jul 2001 17:00:25 GMT Raw View
Hello,
I thought that
class X {};
is a definition, while
class X;
is a declaration.
Now I heard someone talking about a "forward declaration". Can
someone please explain what a forward-declaration is?
Thanks - Martin
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Anthony Williams" <anthwil@nortelnetworks.com>
Date: Thu, 12 Jul 2001 13:02:42 GMT Raw View
"Martin Aupperle" <MikeAlpha@NoSpam_csi.com> wrote in message
news:3b4a9d99.159247515@news.nikoma.de...
> Hello,
>
> I thought that
>
> class X {};
>
> is a definition, while
>
> class X;
>
> is a declaration.
>
> Now I heard someone talking about a "forward declaration". Can
> someone please explain what a forward-declaration is?
A forward declaration is just a declaration. However, it usually refers to
the particular case where something is declared at the top of a source file,
and then declared later in the same source file. This way, anything declared
or defined in between can refer to the object/class/function, as a
declaration (at least) must always be seen before use.
e.g.
int f(int,double); // (forward) declaration
int g()
{
return f(2,3.7); // needs declaration of f() above
}
int f(int a,double d) // definition of f.
{
// do some stuff
return a;
}
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optoelectronics
The opinions expressed in this message are not necessarily those of my
employer
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Stephen Clamage <stephen.clamage@sun.com>
Date: Thu, 12 Jul 2001 19:45:46 GMT Raw View
On Wed, 11 Jul 2001 17:00:25 GMT, MikeAlpha@NoSpam_csi.com (Martin
Aupperle) wrote:
>I thought that
>
> class X {};
>
>is a definition, while
>
> class X;
>
>is a declaration.
>
>Now I heard someone talking about a "forward declaration". Can
>someone please explain what a forward-declaration is?
The terms "declaration" and "definition" when applied to classes have
tradtionally been somewhat muddled. It is common to see
class X { };
referred to as either a declaration or a definition -- sometimes in
the same book or article.
I think it is helpful to maintain the same distinction for classes
that we have for functions, as in your usage above. Using the
terminology that way, a "forward declaration" is just a declaration.
But if you describe
class X { };
as a "declaration", you then need some other term for
class X;
The original C standard uses the term "forward delcaration."
---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]