473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Usage of class forward declarations;

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
Aug 29 '08 #1
3 1016
On 2008-08-29 16:33, Belebele wrote:
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
Aug 29 '08 #2
Belebele <be******@gmail.comkirjutas:
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
Aug 29 '08 #3
Erik Wikström wrote:
On 2008-08-29 16:33, Belebele wrote:
>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.
Aug 29 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Aaron Anodide | last post by:
I ran into a wierd problem today where a case of circular includes caused my build to completely break. All my classes are spit out by a class wizard with "#pragma once" in the header. I...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
7
by: Yngve | last post by:
Hi! I am trying to make two pointers at instances of the same class wich is beeing defined. But i get the following error from the compiler (MVC7): -------------------- ...
28
by: Steven T. Hatton | last post by:
I will assume many people reading this would never create anything similar to the example below. So let me preface this with _*IF*_ you were in a situation where you had to chose between using...
0
by: Leslaw Bieniasz | last post by:
Cracow, 16.09.2004 Hi, I have a problem with compiling the following construction involving cross-calls of class template methods, with additional inheritance. I want to have three class...
4
by: jonathanho15 | last post by:
Sometimes, when I browse through some code, I see declarations like: class SomeClass; These make absolutely no sense to me. Can anyone tell me what these kind of declarations do? Thanks!
11
by: ma740988 | last post by:
I'm perusing a slide with roughly 12 bullets spread across 3 pages. Each bullet reflects 'advice'. I'm ok with all but 1 bullet, more specifically the bullet that states: " Avoid the STL unless...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
9
by: silversurfer2025 | last post by:
Hello everyone, I am currently having problems with a C++ abstract class. I have a class FrameWork.h which defines some methods (of which some are abstract, i.e. virtual void method() = 0). In...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.