🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by David Franke Tue, 10 Oct 1989 14:42
Assignment phase initialization broken with virtual base class
#489
Author: David Franke
Date: Tue, 10 Oct 1989 14:42
80 lines
2527 bytes
	When "virtual public A" is replaced with "public A" in the
	following source code, the program executes as intended.
	With "virtual public A", the result is as shown below.


[2.51]lynx) cat test.cc 
 
#include <stream.h> 
 
class A { 
  int i; 
 public: 
  int j; 
 
  A(int val1, int val2) { i = val1; j = val2; } 
 
  virtual void describe(); 
}; 
 
class B : virtual public A { 
 public: 
  int k; 
 
  B(int i) : A(42,43) { k = i; } 
 
  virtual void describe(); 
}; 
 
 
void A::describe() 
{ 
  cout << "i = " << i << ", j = " << j << "\n"; 
} 
 
 
void B::describe() 
{ 
  cout << "k = " << k << ", "; 
  this->A::describe(); 
} 
 
 
A v1(10,20); 
A *p1 = &v1; 
B v3(30); 
B *p3 = &v3; 
 
main (int argc, char *argv[]) 
{ 
  A v2(30,40); 
  A* p2 = &v2; 
 
  p1->describe(); 
  p2->describe(); 
  p3->describe(); 
} 


[2.52]lynx) make -f test-makefile
/usr/local/gnu/1.36/bin/g++ -c -g -B/usr/local/gnu/1.36/lib/gcc-  -I/usr/local/gnu/1.36/lib/g++-include -v test.cc -o test.o 
gcc version 1.32 
 /usr/local/gnu/1.36/lib/gcc-cpp -+ -v -I/usr/local/gnu/1.36/lib/g++-include -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 test.cc /tmp/cca09791.cpp 
GNU CPP version 1.36 
 /usr/local/gnu/1.36/lib/gcc-cc1plus /tmp/cca09791.cpp -quiet -dumpbase test.cc -g -version -o /tmp/cca09791.s 
GNU C++ version 1.36.0- (based on GCC 1.35.99) (68k, MIT syntax) compiled by GNU C version 1.36. 
default target switches: -m68020 -mc68020 -m68881 -mbitfield 
 /usr/local/gnu/1.36/lib/gcc-as -mc68020 /tmp/cca09791.s -o test.o 
/usr/local/gnu/1.36/bin/g++ -g -B/usr/local/gnu/1.36/lib/gcc- -v test.o -o test; chmod 775 test 
gcc version 1.32 
 /usr/local/gnu/1.36/lib/gcc-ld -o test -e start -dc -dp -Bstatic /lib/crt0.o /lib/Mcrt1.o -L/usr/local/gnu/1.36/lib test.o -lg++ /usr/local/gnu/1.36/lib/gcc-gnulib -lg -lc 


[2.53]lynx) test 
i = 10, j = 20 
i = 30, j = 40 
i = 131168, j = 43 

 David Franke, MCC CAD Program | ARPA: franke@mcc.com | Phone: [512] 338-3641
 UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!franke
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