473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Forwrard References in MSVC6 vs. Borland 5.5 compilter tools.


MSVC6 (SP5) gives this error when I try to use a non-pointer type to a class
that is forward-referenced:
reo.cpp(8) : error C2027: use of undefined type 'B'

However Borland's free 5.5 compiler successfully compiles the same code
snippet.

/* ----------------------------- */
class B; // forward reference

// class A references B
class A
{
public:
void fn(B b) {} // ##### MSVC6 gives error, whereas Borland does not
#####
};

// class B references A
class B
{
public:
void fn(A a) {}
};

void main() {;}
/* ----------------------------- */
The Microsoft compiler will work if I alter the code by changing the
parameters into pointers (seems the forward ref works with pointers only).
However Borland's forward references work with either way.

I have to assume there is a way to make this work in MSVC6 without altering
the code.
Your suggestions and any helpful pointers (no pun) would be appreciated.

TIA,
--John
Jul 22 '05 #1
6 1797
"John" <johnsnews(RemoveNoSpam)11**@hotmail-RemoveNoSpam.com> wrote in
message news:Lj*******************@news20.bellglobal.com
MSVC6 (SP5) gives this error when I try to use a non-pointer type to
a class that is forward-referenced:
reo.cpp(8) : error C2027: use of undefined type 'B'

However Borland's free 5.5 compiler successfully compiles the same
code snippet.

/* ----------------------------- */
class B; // forward reference

// class A references B
class A
{
public:
void fn(B b) {} // ##### MSVC6 gives error, whereas Borland does
not #####
};

// class B references A
class B
{
public:
void fn(A a) {}
};

void main() {;}
/* ----------------------------- */
The Microsoft compiler will work if I alter the code by changing the
parameters into pointers (seems the forward ref works with pointers
only). However Borland's forward references work with either way.

I have to assume there is a way to make this work in MSVC6 without
altering the code.
Your suggestions and any helpful pointers (no pun) would be
appreciated.

TIA,
--John

Microsoft is right. The code shouldn't compile. Perhaps Borland is letting
you get away with it because fn doesn't actually do anything with its B
argument. Change the code.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #2
"John" <johnsnews(RemoveNoSpam)11**@hotmail-RemoveNoSpam.com> wrote in
message news:Lj*******************@news20.bellglobal.com
MSVC6 (SP5) gives this error when I try to use a non-pointer type to
a class that is forward-referenced:
reo.cpp(8) : error C2027: use of undefined type 'B'

However Borland's free 5.5 compiler successfully compiles the same
code snippet.

/* ----------------------------- */
class B; // forward reference

// class A references B
class A
{
public:
void fn(B b) {} // ##### MSVC6 gives error, whereas Borland does
not #####
};

// class B references A
class B
{
public:
void fn(A a) {}
};

void main() {;}
/* ----------------------------- */
The Microsoft compiler will work if I alter the code by changing the
parameters into pointers (seems the forward ref works with pointers
only). However Borland's forward references work with either way.

I have to assume there is a way to make this work in MSVC6 without
altering the code.
Your suggestions and any helpful pointers (no pun) would be
appreciated.

TIA,
--John

Microsoft is right. The code shouldn't compile. Perhaps Borland is letting
you get away with it because fn doesn't actually do anything with its B
argument. Change the code.
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #3
On Sun, 4 Apr 2004 14:18:20 -0400, "John"
<johnsnews(RemoveNoSpam)11**@hotmail-RemoveNoSpam.com> wrote:

MSVC6 (SP5) gives this error when I try to use a non-pointer type to a class
that is forward-referenced:
reo.cpp(8) : error C2027: use of undefined type 'B'

However Borland's free 5.5 compiler successfully compiles the same code
snippet.

/* ----------------------------- */
class B; // forward reference

// class A references B
class A
{
public:
void fn(B b) {} // ##### MSVC6 gives error, whereas Borland does not
#####
};

// class B references A
class B
{
public:
void fn(A a) {}
};

void main() {;}
/* ----------------------------- */
The Microsoft compiler will work if I alter the code by changing the
parameters into pointers (seems the forward ref works with pointers only).
However Borland's forward references work with either way.

I have to assume there is a way to make this work in MSVC6 without altering
the code.
Your suggestions and any helpful pointers (no pun) would be appreciated.


John Carson is right; Borland allows this, but it is not legal C++. By the
time his post showed up I'd already modified your test program to
demonstrate all it takes to make Borland admit defeat, so here it is:

#include <iostream>
using namespace std;

class B;

class A
{
public:
void fn(B b) { b.speak(); }
};

class B
{
public:
void fn(A a) {}
void speak() { cout << "Woof!" << endl; }
};

int main() { return 0;}
Note: C and C++ are compiled conceptually (if not actually) in one pass, so
in general you can never expect the language to let you use a type in a
manner that would require a compiler to know the size of an object before
it has seen enough information to possibly be able to determine that size.
Thus pointers and references to incomplete types are accepted (since the
only thing the compiler really needs to know is the size of a pointer or
reference.)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #4
On Sun, 4 Apr 2004 14:18:20 -0400, "John"
<johnsnews(RemoveNoSpam)11**@hotmail-RemoveNoSpam.com> wrote:

MSVC6 (SP5) gives this error when I try to use a non-pointer type to a class
that is forward-referenced:
reo.cpp(8) : error C2027: use of undefined type 'B'

However Borland's free 5.5 compiler successfully compiles the same code
snippet.

/* ----------------------------- */
class B; // forward reference

// class A references B
class A
{
public:
void fn(B b) {} // ##### MSVC6 gives error, whereas Borland does not
#####
};

// class B references A
class B
{
public:
void fn(A a) {}
};

void main() {;}
/* ----------------------------- */
The Microsoft compiler will work if I alter the code by changing the
parameters into pointers (seems the forward ref works with pointers only).
However Borland's forward references work with either way.

I have to assume there is a way to make this work in MSVC6 without altering
the code.
Your suggestions and any helpful pointers (no pun) would be appreciated.


John Carson is right; Borland allows this, but it is not legal C++. By the
time his post showed up I'd already modified your test program to
demonstrate all it takes to make Borland admit defeat, so here it is:

#include <iostream>
using namespace std;

class B;

class A
{
public:
void fn(B b) { b.speak(); }
};

class B
{
public:
void fn(A a) {}
void speak() { cout << "Woof!" << endl; }
};

int main() { return 0;}
Note: C and C++ are compiled conceptually (if not actually) in one pass, so
in general you can never expect the language to let you use a type in a
manner that would require a compiler to know the size of an object before
it has seen enough information to possibly be able to determine that size.
Thus pointers and references to incomplete types are accepted (since the
only thing the compiler really needs to know is the size of a pointer or
reference.)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #5
John wrote:

void main() {;}
/* ----------------------------- */


Additional note: main() must return int, even if your compiler
mistakenly allows void. This is explicitly required by the standard.
void is not and never has been an acceptable return type for main().

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #6
John wrote:

void main() {;}
/* ----------------------------- */


Additional note: main() must return int, even if your compiler
mistakenly allows void. This is explicitly required by the standard.
void is not and never has been an acceptable return type for main().

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #7

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

Similar topics

0
by: Bill Davy | last post by:
I am building a C++ program (main.exe) with VC6 which expects to call the Python DLL. When I start it (under the debugger), I get: "This application has failed to start because python24_d.dll was...
17
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using...
7
by: Developwebsites | last post by:
do they have 5.5 with an IDE? I've used 3.1 and 4.52, so why should i go back to command line with 5.5? are there any other C++ compilers with an IDE? ...
2
by: Developwebsites | last post by:
I have tried out these C++ compilers: Watcom 11.0c - simply does not work. now they bundled fortran with c++ but it just doesnt install on my pc. digi-mars DOS - good, fast, small. however, no...
0
by: Danny Deen | last post by:
Hello everyone, --------------- I'm looking to buy any or all of the following MS-DOS compilers: ================================== ------------------------------------------ (I) Microsoft...
0
by: Vera | last post by:
Hi, I have a very annoying problem, with which I NEED HELP DESPERATELY!! It smells like a bug to me, but I'm not sure. SITUATION This description is a very much simplified version of the real...
5
by: John | last post by:
MSVC6 (SP5) gives this error when I try to use a non-pointer type to a class that is forward-referenced: reo.cpp(8) : error C2027: use of undefined type 'B' However Borland's free 5.5 compiler...
2
by: Michelle Collier-Moore | last post by:
Please could someone offer some advice regarding adding references to an Access database? I tried to open a project a few days ago sent to me by someone whose developer had left the company. I...
5
by: christian | last post by:
Hi! I have a problem with a template function im MSVC6 the template function is defined as: template <__Type1, __Type2> int MyFunc(int param1, double param2) {__Type1 var1; __Type2 var2; ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.