Topic: Proposal: implicit virtual member for polymorphic types
Author: "Philippe A. Bouchard" <philippeb@videotron.ca>
Date: Tue, 27 Aug 2002 11:15:14 CST Raw View
Hi,
I would like to suggest to add an implicit virtual member function that
will return the address of the first grandfather it can find for polymorphic
types (given: grandfather = leftmost parent). The functionality would be a
lot similar to delete() thru virtual destructors:
#include <iostream>
using namespace std;
struct A { virtual ~A() {} virtual void * implicit() { return this; } };
struct B : A { virtual ~B() {} virtual void * implicit() { return this; } };
struct C : A { virtual ~C() {} virtual void * implicit() { return this; } };
struct D : B, C { virtual ~D() {} virtual void * implicit() { return
this; } };
int main()
{
void * pV = new D;
cout << "pV = " << pV << endl;
// Ex.: pV = 0x80000000
A * pA = (A*) (C *) (D *) (pV);
cout << "pA = " << pA << endl;
// Ex.: pA = 0x80000004
cout << pA->implicit() << endl;
// Ex.: pA->implicit() = 0x80000000
return 0;
}
_That_ would help a lot and I'm sure other people would agree (including
boost::ptr<T>'s author...).
Thanks,
Philippe A. Bouchard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]