nullnullc++虚表 内存分配
时间紧张,先记一笔,后续优化与完善。
#include
<iostream>
#include
<stdlib.h>
#include
<windows.h>
using
namespace
std
;
class
A
{
char
a
;
public
:
A
(){
a
=
'a'
;
cout
<<
"is
A
construct
function"
<<
endl
;}
~
A
(){
cout
<<
"is
A
Unconstruct
function"
<<
endl
;}
virtual
void
f
(){
cout
<<
"im
A
v_table"
<<
endl
;}
};
class
A1
{
char
b
;
public
:
A1
(){
b
=
'b'
;
cout
<<
"is
A1
construct
function"
<<
endl
;}
~
A1
(){
cout
<<
"is
A1
Unconstruct
function"
<<
endl
;}
virtual
void
f
(){
cout
<<
"im
A1
v_table"
<<
endl
;}
};
class
B
:
public
A
,
public
A1
{
char
c
;
public
:
B
(){
c
=
'c'
;
cout
<<
"is
B
construct
function"
<<
endl
;}
~
B
(){
cout
<<
"is
B
Unconstruct
function"
<<
endl
;}
virtual
void
f1
(){
cout
<<
"im
B
v_table"
<<
endl
;}
};
typedef
void
(*
Fun
)(
void
);
int
main
()
{
B
b
;
char
*
p
=
(
char
*)(&
b
);
cout
<<
sizeof
(
b
)<<
endl
;
Fun
pFun
=
NULL
;
pFun
=
(
Fun
)*((
int
*)*(
int
*)(&
b
));
pFun
();
pFun
=
(
Fun
)*((
int
*)*(
int
*)(&
b
)+
1
);
pFun
();
pFun
=
(
Fun
)*((
int
*)*(
int
*)(
p
+
8
));
pFun
();
for
(
int
i
=
0
;
i
<
16
;
i
++)
cout
<<
"i:"
<<
i
<<
"
"
<<(*(
p
+
i
))<<
endl
;
system
(
"pause"
);
return
1
;
}
文章结束给大家分享下程序员的一些笑话语录: N多年前,JohnHein博士的一项研究表明:Mac用户平均IQ要比PC用户低15%。超过6000多的参加者接受了测试,结果清晰的显示IQ比较低的人会倾向于使用Mac。Mac用户只答对了基础问题的75%,而PC用户却高达83%。