-
-
[原创]C++类成员指针调用
-
2022-1-25 17:21 3765
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <iostream> template<typename dst_type, typename src_type> dst_type pointer_cast(src_type src) { return * static_cast<dst_type * >(static_cast<void * >(&src)); } class aa; typedef int (aa:: * pfun)( int ); class aa { public: aa() { } int push(void * f) { m_fun = f; return 0 ; } int afun( int a) { pfun f = pointer_cast<pfun>(m_fun); return (this - > * f)(a); } public: void * m_fun; }; class bb : public aa { public: int bfun( int a) { printf( "%d\n" , a); return 0 ; } }; int main() { bb b; b.push(pointer_cast<void * >(&bb::bfun)); aa * a = &b; a - >afun( 5 ); return 0 ; } |
赞赏
他的文章
[原创]C++类成员指针调用
3766
[原创]VMP3.2授权分析
51630
[原创]看雪CTF2017 第十二题分析
4599
[原创]看雪CTF2017 第十一题分析
5767
[原创]看雪CTF2017 第十题分析
5263
看原图