Article View: gnu.gcc.help
Article #51018virtual classes
From: haeckel
Date: Tue, 13 Jul 1993 10:45
Date: Tue, 13 Jul 1993 10:45
75 lines
2508 bytes
2508 bytes
Hi Mr/Mrs help-gcc,
I am compiling and debugging with the gcc 2.4.5, gdb and gmake at the
Technical University in Karlsruhe, Germany. Very good tools, they
satisfy all my needs and wiches. They really make the DEC3100-station I
work with more powerfull.
But now I found a behaviour of the compiler that I don't like and ask
you for help:
I use virtual classes so there should exist only one copy of its
attributes (data) even if this classes are parent class (base class) of
more than one children classes. I don't know why, but I did not manage
to tell the gcc to make only one copy of this virtual classes. Can somebody help me?
Here is an example of an c-source behaving this way:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include <stdio.h>
class hello {
private : int i;
public:
void put (int ar) {
i = ar;
printf ("hello world\n");
}
};
class greet : public virtual hello {
private: int j;
public:
void put1 (int ar) {
j = ar;
printf ("i'm greeting you!\n");
}
};
class bye : public virtual hello, public virtual greet {
private: int k;
public:
void put2 (int ar) {
k = ar;
printf ("bye\n");
}
};
bye h;
int main (void) {
h.hello::put (1);
h.greet::put1 (2);
h.greet::put (3);
h.bye::put2 (4);
h.bye::put1(5);
h.bye:: put (6);
return 0;
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I compiled this program using the gcc 2.4.5 on a DEC DS3100 with Ultrix
V4.2A (Rev. 47). The commandline was "gcc -g hello.C". Inspecting the
code with gdb version 4.9 shows, that there exist 2 copies of hello. I
do want exactly one copy of hello, and I want to be able to reach the
method "put" in the class "bye"!
Who can help me to overcome the problem? Do you need more information?
bye, Arne Haeckel
Technical Details
Message-ID:
<9307131039.AA08137@t524i3.telematik.informatik.uni-karlsruhe.de>Path:
arc1-ca.pugleaf.net!gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!t524i3.telematik.informatik.uni-karlsruhe.de!haeckelShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,f0cc7c9be7d03dc5,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-07-13 03:56:51 PST Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!t524i3.telematik.informatik.uni-karlsruhe.de!haeckel From: haeckel@t524i3.telematik.informatik.uni-karlsruhe.de Newsgroups: gnu.gcc.help Subject: virtual classes Date: 13 Jul 1993 06:45:36 -0400 Organization: GNUs Not Usenet Lines: 75 Sender: daemon@cis.ohio-state.edu Distribution: gnu Message-ID: <9307131039.AA08137@t524i3.telematik.informatik.uni-karlsruhe.de>