在大型项目中,很容易出现版本不匹配的问题,其中导致的虚函数飘移的问题比较难解决。
在这里,用一个例子来说明如何解决这种问题。
建立三个源文件:testso.h,testso.cpp,xuzhina_dump_c6_s3_ex.cpp。
testso.h的代码如下:
1 #ifndef __TESTSO_H__
2 #define __TESTSO_H__
3
4 class xuzhina_dump_c6_s3_ex
5 {
6 public:
7 virtual char* encode( char* str );
8 };
9
10 #endif
testso.cpp的代码如下:
1 #include <string.h>
2 #include "testso.h"
3
4 char* xuzhina_dump_c6_s3_ex::encode( char* str )
5 {
6 return str;
7 }
8
xuzhina_dump_c6_s3_ex.cpp的代码如下:
1 #include <stdio.h>
2 #include "testso.h"
3
4 int main()
5 {
6 char* hello = (char*)"hello";
7 xuzhina_dump_c6_s3_ex* test = new xuzhina_dump_c6_s3_ex;
8
9 char* p = test->encode( hello );
10
11 printf( "the second char:%c\n", p[1] );
12
13 return 0;
14 }
更多内容请关注微信公众号“debugeeker", 链接为https://mp.weixin.qq.com/s/tunZvO_Btt5w1f4kWqm2Kw