🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #819

Re: Is this code using casts valid in C++ ?

#819
From: 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.
Technical Details
Message-ID: <3789@lupine.NCD.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!infopiz!lupine!rfg
References: <5217@s3.ireq.hydro.qc.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!infopiz!lupine!rfg
From: rfg@NCD.COM (Ron Guilmette)
Newsgroups: comp.std.c++
Subject: Re: Is this code using casts valid in C++ ?
Message-ID: <3789@lupine.NCD.COM>
Date: 8 Feb 91 06:07:52 GMT
References: <5217@s3.ireq.hydro.qc.ca>
Organization: Network Computing Devices, Inc., Mt. View, CA
Lines: 23