🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tom Keffer Tue, 25 Jul 1989 18:55
Explicit conversion of derived* to a base*
#296
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads