Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Inheritance and references question Message-ID: <71133@microsoft.UUCP> Date: 7 Mar 91 21:25:23 GMT References: <1991Feb26.060459.6777@csun.edu| <71032@microsoft.UUCP> <1991Mar5.010600.19687@world.std.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 47 In article <1991Mar5.010600.19687@world.std.com> wmm@world.std.com (William M Miller) writes: |jimad@microsoft.UUCP (Jim ADCOCK) writes: |> I don't like this definition, mind you. I'd like the pertinent section |> in 8.4.3 to say: |> |> If the initializer for a reference to type T is an lvalue of type T or of |> a type derived from T for which T is an accessible base or if T and the |> initializer are pointers or references to such, then the reference |> will refer to the initializer... | |NO. This is a BAD idea and opens a gaping hole in the type system as bad as |C's allowing assignment of void* pointers to typed pointers without casts. |Consider the following example: I agree, it was a bad idea. I can't remember *what* I was thinking! |The whole idea behind |the C++ type system is that if you do type-insecure things, you ought to |have to use an explicit cast to indicate that you know what you're doing; |there are no casts in the above code, even though it's terribly |type-insecure. I agree that this *ought* to be how C++ works, but unfortunately, the automatic *implicit* "cast" of an array formal argument to a pointer to its first element violates these rules of type safety: void zero10000ints(int ar[10000]) { for (int i=0; i<10000; ++i) ar[i] = 0; } main() { int ar[10]; zero10000ints(ar); // oops, run-time crash! return 0; } Are you lobbying the ANSI-C++ committee to fix this obvious hole in C++'s type safety? [The way C++ *ought* to work in this situation is that an array formal argument is *implicitly* converted to a reference to an array of the same type. That way the C tradition that arrays are passed by reference would be maintained, and C++ could be a type-safe language]