🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Louis Lamarche Tue, 05 Feb 1991 00:39
Is this code using casts valid in C++ ?
#811
Author: Louis Lamarche
Date: Tue, 05 Feb 1991 00:39
17 lines
1037 bytes
class foo { int a; };
class foob : public foo { int b; };
foo afoo;
foo* afooPtr = &afoo;
foob* afoobPtr = (foob*) afooPtr;
foo& afooRef = afoo;
foob& afoobRef = (foob&) afooRef;  // Ok with g++1.37.0, rejected by g++1.37.2-
main(){}

This code compiles well with CC 2.0 on a Sun and with Zortech 2.1, but fails
with g++1.37.2-. Is it legal ?

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
| Louis Lamarche, IREQ |       lamarche@IREQ.Hydro.Qc.CA
| CP 1000, Varennes    |                 or
| QC, Canada, J3X 1S1  |  514-652-8077 (office)  514-324-2919 (home)
Re: Is this code using casts valid in C++ ?
#819
Author: Ron Guilmette
Date: Fri, 08 Feb 1991 06:07
23 lines
1179 bytes
In article <5217@s3.ireq.hydro.qc.ca> lamarche@ireq.hydro.qc.ca (Louis Lamarche) writes:
+class foo { int a; };
+class foob : public foo { int b; };
+foo afoo;
+foo* afooPtr = &afoo;
+foob* afoobPtr = (foob*) afooPtr;
+foo& afooRef = afoo;
+foob& afoobRef = (foob&) afooRef;  // Ok with g++1.37.0, rejected by g++1.37.2-
+main(){}
+
+This code compiles well with CC 2.0 on a Sun and with Zortech 2.1, but fails
+with g++1.37.2-. Is it legal ?

No.  That's illegal.

In your example, a `foob' is a `foo' but not vise-versa.  Thus, you may
convert a `foob&' to a `foo&' but not vise-versa.

-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads