🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: pointer conversions from the null pointer

#3358
From: Steve Clamage
Date: Tue, 20 Feb 1996 21:32
44 lines
1854 bytes
In article 8J1@netcom.com, balu@netcom.com (Balasubramanian) writes:
>Given the following:

>class A {};
>class B : public A {};
>class C : public B {};

>void foo(A*) { ... }

>void foo(C*) { ... }

>int main() {foo(0); return 0;}

>How is the call to foo() in main() to be resolved? It seemed obvious
>to me that the call should be ambiguous ...

It seems obvious to me too. The null pointer constant is an exact match
for any pointer, so there is no reason to prefer either version of foo.

There is a preference associated with class hierarchies. For example:
	class X { ... };
	class Y : public X { ... };
	class Z : public Y { ... };
	void foo(X*);
	void foo(Y*);

	Z* pz = ...;
	foo(pz);

A Z* can be converted to either a Y* or an X*, but Y* is preferred. This
case does not apply to null pointer constants, however, since a null
pointer constant does not have type Z*.

---
Steve Clamage, stephen.clamage@eng.sun.com



[ To submit articles: Try just posting with your newsreader.
		      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID: <4gddco$cqv@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <baluDn1pGL.8J1@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: pointer conversions from the null pointer
Date: 20 Feb 1996 21:32:36 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4gddco$cqv@engnews1.Eng.Sun.COM>
References: <baluDn1pGL.8J1@netcom.com>
Reply-To: clamage@Eng.sun.com
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 928
X-Lines: 37
Originator: clamage@taumet