Usage of class forward declarations;

B

Belebele

Why is the code below giving an error in VC++ 8? Why would the
compiler need to see the definition of Foo to compile:

class Foo;
Foo& g();
void f()
{
g(); // error: use of undefined type 'Foo'
}


?

Thanks
 
E

Erik Wikström

Why is the code below giving an error in VC++ 8? Why would the
compiler need to see the definition of Foo to compile:

class Foo;
Foo& g();
void f()
{
g(); // error: use of undefined type 'Foo'
}

Because g() returns an object of type Foo, which means that the compiler
needs to know how to create such an object.
 
J

Juha Nieminen

Erik said:
Because g() returns an object of type Foo, which means that the compiler
needs to know how to create such an object.

Actually it returns a reference of type Foo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top