指针比较

本文内容来源:《C++必知必会》  条款28

1 #include <stdio.h>
2 class A{
3 public:
4 int a;
5 };
6
7 class B{
8 public:
9 int b;
10 };
11
12 class C: public A, public B{
13 public:
14 int c;
15 };
16 int main(int argc, char **argv)
17 {
18 C *pc = new C();
19 A *pa = pc;
20 B *pb = pc;
21 void *p = (void *)pc;
22 //by now, pc == pa is true, pc == pb is true, pa == pb not valid, compile error
23 // p == pc is true , p == pa is true(compiler dependent), p == pb is false (all of them are raw pointer comparison)
24 return 0;
25 }

posted on 2011-05-25 18:05  Joshua Leung  阅读(245)  评论(0编辑  收藏  举报

导航