- #include <bitset>
- #include <iostream>
- using namespace std;
- inline std::string methodName(const std::string& prettyFunction)
- {
- size_t colons = prettyFunction.find("::");
- size_t begin = prettyFunction.substr(0,colons).rfind(" ") + 1;
- size_t end = prettyFunction.rfind("(") - begin;
- return prettyFunction.substr(begin,end) + "()";
- }
- #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__)
- class BaseA
- {
- public:
- virtual void Show() { cout << __METHOD_NAME__ << endl; }
- private:
- virtual void Display() { cout << __METHOD_NAME__ << endl; }
- };
- class BaseB
- {
- public:
- virtual void Show() { cout << __METHOD_NAME__ << endl; }
- private:
- virtual void Display() { cout << __METHOD_NAME__ << endl; }
- };
- class BaseC
- {
- public:
- virtual void Show() { cout << __METHOD_NAME__ << endl; }
- private:
- virtual void Display() { cout << __METHOD_NAME__ << endl; }
- virtual void Hello() { cout << __METHOD_NAME__ << endl; }
- };
- typedef void (*PFunc)() ;
- class Device: public BaseA, public BaseB,public BaseC
- {
- };
- int main( int argc, const char *argv[] )
- {
- Device d;
- int** pVTab = (int**)&d;
- int fIndx = 0;
- int tabIndx = 0;
- while(1)
- {
- if( pVTab[ tabIndx ][ fIndx ] == 0 ) // MINGW-gcc >= 4.7: VTable end flag is 0
- {
- break;
- }
- else if( pVTab[ tabIndx ][ fIndx ] < 0 ) // MINGW-gcc >= 4.7: has another VTable flag is -4
- {
- tabIndx += 1;
- fIndx = 0;
- }
- PFunc func = (PFunc)pVTab[ tabIndx ][ fIndx ];
- cout << pVTab[ tabIndx ][ fIndx ]<<":";
- func();
- fIndx += 1;
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/130120148504.html
来源: http://www.codesnippet.cn/detail/130120148504.html