lamarche@ireq.hydro.qc.ca (Louis Lamarche) (02/05/91)
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)rfg@NCD.COM (Ron Guilmette) (02/08/91)
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.