From -8445749107042931555
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,388934337992c65c,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,388934337992c65c,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-04-03 07:13:43 PST
Xref: sparky comp.std.c++:362 comp.lang.c++:6469
Newsgroups: comp.std.c++,comp.lang.c++
Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!tfs.com!tfs.com!eric
From: eric@tfs.com (Eric Smith)
Subject: Re: Overloading and 0
Message-ID: <1992Apr3.151343.26700@tfs.com>
Keywords: overloading, NULL, ambiguity
Organization: TFS
References: <1992Apr2.153121.4155@wam.umd.edu>
Date: Fri, 3 Apr 1992 15:13:43 GMT
Lines: 42

In article <1992Apr2.153121.4155@wam.umd.edu> krc@wam.umd.edu (Kevin R. Coombes) writes:
>I just ran into a problem with the following code:
>
>class B;
>
>class A {
>  private:
>    A(B *);
>  public:
>    A(long);
>};
>
>A a(0);
>
>(This is, of course, a simplified example.) I used two different
>compilers. The first compiler did what I expected. It silently
>compiled the definition of the object "a" using the constructor
>A(long), and went on to compute the correct answer. (I know it was
>correct; this was a test of the class.) The second compiler refused
>to compile. It claimed two errors at this line.
>
>First, it claimed the call was ambiguous, since it could not decide
>which constructor to use. Second, it pointed out that the constructor
>A(B *) was not accesible. The second complaint I have no problem with.
>The first one, however, keeps raising more questions the longer I think
>about it.
>
>Question 1. Which of the compilers implements the "correct" behavior?
>Here correct may be taken to mean either sanctioned by the ARM or to
>mean it ought to become part of the ANSI standard.

The first compiler was wrong, the 2nd compiler was right.  "A a(0);"
should be detected as an error.  A human reader would have trouble
deciding exactly what you meant by "A a(0);", because it looks more
like a mistake than a correct invocation of your constructor.  The
human reader, like the compiler, must always keep in mind that the
construct might be an error.

The proper solution to this problem is to make your code clearer to
both the human reader and the compiler, by putting an explicit cast on
the zero: "A a((long)0);" or "A a=(long)0;", or you can abbreviate it
in this case by using the suffix "L", e.g. "A a(0L);".


