🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++.moderated
Article #58

Re: Simple inheritance Q

#58
From: Stephen C. Marney
Date: Fri, 01 Mar 1996 13:31
37 lines
1556 bytes
Eric Simon wrote:
> 
> I have a base class, called Animal, and a derived class, called Cat.
> 
> In my main program I have:
> 
> 1.    Animal *p;
> 2.    Cat a(args);
> 3.    p = &a;
> 
> Now, if I define
>     class Cat:Animal{...
> 
> then I get the error in line 3:
>   Can not convert Cat * to Animal *
> 
> But if I define
>    class Cat:public Animal{...
> 
> everything is fine.
> 
> Can anyone tell me why?
> 	[clip]

The default access for classes is private.
p = &a; 	// asks for an implicit conversion.

"Pointers and references to derived classes can be implicitly converted to
pointers and references 
to their base classes if there is an accessible, unambiguous base class."

Key word in this case is accessible (i.e., at least, not private.)

      [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
      [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
      [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
      [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
Technical Details
Message-ID: <4h6u6m$qto@netlab.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mail
References: <4gumo0$hta@netlab.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!library.erc.clarkson.edu!rpi!not-for-mail
From: "Stephen C. Marney" <scmarney@erols.com>
Newsgroups: comp.lang.c++.moderated,comp.lang.c++
Subject: Re: Simple inheritance Q
Date: 1 Mar 1996 13:31:02 -0000
Organization: Techsyn Company
Sender: cppmods@netlab.cs.rpi.edu
Approved: herbs@connobj.com
Message-ID: <4h6u6m$qto@netlab.cs.rpi.edu>
References: <4gumo0$hta@netlab.cs.rpi.edu>
NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: Thu, 29 Feb 1996 23:44:54 -0500