avatar
m*o
1
class C{ virtual void proc (int x) {...}..};
..
C obj;
C* ptr;
..
obj.proc(5); //(1)
ptr->proc(5); //(2)
请问1和2的却别,2要比1多执行几步机器指令?
avatar
g*n
2
For obj.proc(5):
1. calculat the address of obj, and push this address onto the stack (or
load it into a registary). Member function requires "this" pointer.
2. push 5 onto the stack (or load it into a registary).
3. call C::proc(int). Assuming compiler is smart enough to de-virtual the
call to proc.
For ptr->proc(5):
1. push the value of ptr onto the stack (or load it into a registary).
2. push 5 onto the stack (or load it into a registary).
3. get the enry address from vtable.
4. call C::proc
avatar
m*o
3
哥们真牛,以后去做QUANT DEVELOPER吧,最高年薪100万
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。