what are forward declarations

Discussion in 'C++' started by Neo, Nov 21, 2005.

  1. Neo

    Neo Guest

    Hi,
    I am new to C++ and want to know what are forward declarations and any
    site which has a good introductory explanation.

    thanks in advance,
    nick
    Neo, Nov 21, 2005
    #1
    1. Advertising

  2. Neo

    Jim Langston Guest

    "Neo" <> wrote in message
    news:...
    > Hi,
    > I am new to C++ and want to know what are forward declarations and any
    > site which has a good introductory explanation.
    >
    > thanks in advance,
    > nick


    See this and others:
    http://www.parashift.com/c -faq-lite/misc-technical-issues.html#faq-39.11

    Basically:
    // This won't compile because SomeFunction hasn't been declared before it's
    used,
    // so the compiler doesn't know how it's supposed to be used.
    void main()
    {
    SomeFunction();
    }

    void SomeFunction()
    {
    // Do Something
    }

    // This will compile
    SomeFunction(); // This is a forward declaration
    void main()
    {
    SomeFunction();
    }

    void SomeFunction()
    {
    // Do Something
    }
    Jim Langston, Nov 21, 2005
    #2
    1. Advertising

  3. On 2005-11-21 20:05, Neo wrote:
    > Hi,
    > I am new to C++ and want to know what are forward declarations and any
    > site which has a good introductory explanation.
    >
    > thanks in advance,
    > nick


    Forward declarations is a way to tell the compiler that there exists a
    class with a certain name, but you don't tell it what it is.

    A good example and explanation from the FAQ:
    http://www.parashift.com/c -faq-lite/misc-technical-issues.html#faq-39.11

    Erik Wikström
    --
    "I have always wished for my computer to be as easy to use as my
    telephone; my wish has come true because I can no longer figure
    out how to use my telephone" -- Bjarne Stroustrup
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Nov 21, 2005
    #3
    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. matthew polder

    namespaces and forward declarations

    matthew polder, Jul 24, 2003, in forum: C++
    Replies:
    1
    Views:
    353
    John Harrison
    Jul 24, 2003
  2. mjm
    Replies:
    3
    Views:
    395
  3. whithers
    Replies:
    4
    Views:
    372
    Sumit Rajan
    Jan 16, 2004
  4. Alan Lee
    Replies:
    5
    Views:
    357
    Rolf Magnus
    Apr 5, 2004
  5. Steven T. Hatton

    forward declarations and namespaces?

    Steven T. Hatton, Apr 27, 2004, in forum: C++
    Replies:
    6
    Views:
    3,227
    Dave Moore
    May 5, 2004
Loading...

Share This Page