Topic: pointer to data member of virtual base class
Author: tom@ssd.hcsc.com (Tom Horsley)
Date: 1996/07/02 Raw View
We have been reading various documents like the ARM (ancient, I know), and a
copy of the draft standard (not quite as ancient), and have not found any
statement we can interpret as outlawing the practice of making a pointer to
data member for a data member that happens to be a member of a virtual base
class.
On the other hand, when trying a test program, every compiler I can get my
hands on, says it is an error (or at least says it is too complicated to
implement :-).
So which is it? Does the standard actually outlaw it, and I am too dense to
interpret it correctly? Or is is supposed to be legal, but most compilers
gag on it? (By the way, I would just as soon have it be illegal so that
a pointer to data member really could be implemented as a simple offset).
For reference, here is my test program. The lines with a 'gag' comment are
the ones the compilers I have tried cannot handle.
#include <stdio.h>
class vb1 {
public:
int vb1x;
};
class vb2 {
public:
int vb2x;
};
class der1 : public virtual vb1, public virtual vb2 {
public:
int der1x;
};
int
ShiftVal(class der1 * der1p, int der1::* pmi, int newval)
{
int oldval = der1p->*pmi;
der1p->*pmi = newval;
return oldval;
}
class der2 : public der1, public virtual vb1 {
public:
int der2x;
};
class der3 : public der1, public virtual vb2 {
public:
int der3x;
};
int
main(int argc, char ** argv)
{
der2 d2;
der3 d3;
d2.vb1x = 47;
d2.vb2x = 48;
d2.der1x = 49;
d2.der2x = 50;
d2.vb1x = 51;
d2.vb2x = 52;
d2.der1x = 53;
d3.der3x = 55;
printf("%d\n", ShiftVal(&d2, &der1::vb1x, -12)); // gag
printf("%d\n", ShiftVal(&d3, &der1::vb2x, -13)); // gag
printf("%d\n", ShiftVal(&d2, &der1::der1x, -14));
printf("%d\n", ShiftVal(&d3, &der1::vb1x, -15)); // gag
printf("%d\n", ShiftVal(&d2, &der1::vb2x, -16)); // gag
printf("%d\n", ShiftVal(&d3, &der1::der1x, -17));
}
--
--
Tom.Horsley@mail.hcsc.com or Tom.Horsley@worldnet.att.net
Work: Concurrent Computers, 2101 W. Cypress Creek Rd. Ft. Lauderdale FL 33309
The 2 most important political web sites: http://www.vote-smart.org (Project
Vote Smart), and http://ourworld.compuserve.com/homepages/TomHorsley (Me!)
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]