Connecting Tech Pros Worldwide Forums | Help | Site Map

Usage of class forward declarations;

Belebele
Guest
 
Posts: n/a
#1: Aug 29 '08
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

=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
 
Posts: n/a
#2: Aug 29 '08

re: Usage of class forward declarations;


On 2008-08-29 16:33, Belebele wrote:
Quote:
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.

--
Erik Wikström
Paavo Helde
Guest
 
Posts: n/a
#3: Aug 29 '08

re: Usage of class forward declarations;


Belebele <beluchin@gmail.comkirjutas:
Quote:
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'
}
>
This compiles with gcc and Comeau online, so I guess this is a VC++ bug.

regards
Paavo
Juha Nieminen
Guest
 
Posts: n/a
#4: Aug 29 '08

re: Usage of class forward declarations;


Erik Wikström wrote:
Quote:
On 2008-08-29 16:33, Belebele wrote:
Quote:
>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.
Actually it returns a reference of type Foo.
Closed Thread