🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #296

Explicit conversion of derived* to a base*

#296
From: Tom Keffer
Date: Tue, 25 Jul 1989 18:55
32 lines
1241 bytes
//The following code is from Stroustrup, p. 197.  If you believe in God,
//it should compile.

//It involves manipulating private base classes through pointers.

class base {
  int m1;
public:
  int m2;
};

class derived : base {
};

main(){
  derived d;
  base * pb;
  pb = (base*)&d;      // Explicit conversion
}


Gives the following error (g++ 1.35.0; Sun3; SunOS 3.5):

In function int main ():
junk.cc:19: type `derived' is derived from private `base'

---
 Dr. Thomas Keffer          | Internet: keffer@sperm.ocean.washington.edu
 School of Oceanography     | BITNET:   keffer%sperm.ocean.washington.edu@UWAVM
 Univ. of Washington, WB-10 | uucp:     uw-beaver!sperm.ocean.washington.edu!keffer
 Seattle, WA 98195          | Telemail: T.KEFFER/OMNET
    (206) 543-6455
Technical Details
Message-ID: <8907251855.AA01996@sperm.ocean.washington.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!SPERM.OCEAN.WASHINGTON.EDU!keffer

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!SPERM.OCEAN.WASHINGTON.EDU!keffer
From: keffer@SPERM.OCEAN.WASHINGTON.EDU (Tom Keffer)
Newsgroups: gnu.g++.bug
Subject: Explicit conversion of derived* to a base*
Message-ID: <8907251855.AA01996@sperm.ocean.washington.edu>
Date: 25 Jul 89 18:55:38 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 32