RE: [Dev-C++] C++ Virtual function Tables and Implementation - Complet ed Code listing
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <eng...@ju...> - 2004-06-09 05:21:28
|
Hi,
I'm sorry for not showing all of the code. Here it is:
class InternetConnection {
public:
............virtual int iconnect(...) =0; //Pure Virtual Method
};
class DSLConnection : public InternetConnection {
public:
............virtual int iconnect(...); //definition not shown
};
class ISDNConnection : public InternetConnection {
public:
............virtual int iconnect(...); //definition not shown
}
class DailupConnection : public InternetConnection {
public:
............. virtual int iconnect(...); //definition not shown
};
//////////////////////////////////////////////////////////////////////
////This class is not derived from InternetConnection
//////////////////////////////////////////////////////////////////////
class ExportedConnection {
public:
.........virtual int iconnect(...); //definition not shown
};
int main() {
InternetConnection *ic = new DSLConnection; //Derived from InternetConnection
InternetConnection *ic2 = new DailupConnection; //Derived from InternetConnection
ExportedConnection exported_object; //Not Derived from InternetConnection
ic->iconnect();
ic2->iconnect();
delete ic;
delete ic2;
//The cast to void* then assignment
(void*)ic=&exported_object; //Virtual function table pointer assignment via cast to void*
ic->iconnect(); //exported_object's method called
return 0;
}
This compiles on Linux using g++, Borland C++ and works with Borland Delphi and Borland C++ class objects. The VC++ compiler is implemented differently so Borland and VC++ objects might not work.
Thanks,
Jim E. Smith
________________________________________________________________
The best thing to hit the Internet in years - Juno SpeedBand!
Surf the Web up to FIVE TIMES FASTER!
Only $14.95/ month - visit www.juno.com to sign up today!
|