摘要:
这是针对前文的问题的回答。本文强调的是为什么在“执行期”调整,而不是为什么要调整。类层次:1 class A {...}2 3 class B {...}4 5 class C: public A, public B {...}6 7 B* b = new C;8 9 b->foo(); //virtual function在这种情况下,是需要在执行期调整作为参数的this指针的,以例其指向真正的C对象,也就是前文提到的两种方法。为什么编译期不能决定this指针的偏移呢?因为编译期无法确定b指向的真正对象。不需要调整this指针的情况1 B *b = new B;2 3 b->fo 阅读全文
posted @ 2011-04-18 16:47
lbsx
阅读(868)
评论(1)
推荐(0)
摘要:
1 class A {...}2 3 class B {...}4 5 class C: public A, public B {...}6 7 B* b = new C;8 9 b->foo(); //virtual function在为line 9实现多态的时候,b指向的不是C对象的开头,而是其subobject B的开头。因此在调用foo时,作为参数的this指针需要被调整,以指向真正的C对象的开始。在《Inside the C++ Object Model》一书中,Lippman提到了两种方案,一种是在虚函数表中不光存放真正调用函数的地址,还存上需要对this指针进行调整的偏移, 阅读全文
posted @ 2011-04-18 16:06
lbsx
阅读(1424)
评论(0)
推荐(1)
摘要:
http://code.alexreisner.com/articles/character-encoding.html对于以UTF-8编码的字节:if it starts with 0it’s an ASCII characterif it starts with 10it’s a continuation of a multi-byte characterif it starts with 110it’s the first byte of a 2-byte characterif it starts with 1110it’s the first byte of a 3-byte ch 阅读全文
posted @ 2011-04-18 15:56
lbsx
阅读(284)
评论(0)
推荐(0)
浙公网安备 33010602011771号