473,385 Members | 1,867 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,385 software developers and data experts.

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 1791
"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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.