出道题给大家玩玩
闲来无聊,出道题给大家玩一玩.只博一哂,呵呵
#include <stdio.h>
class A
{
public:
int m_a;
};
class B : public A
{
public:
int m_b;
void virtual fun() {}
};
int main()
{
B b;
B* pb = &b;
A* pa = pb;
void *pb2 = (void *)pb;
void *pa2 = (void *)pa;
const char *str1 = (pa==pb) ? "yes" : "no";
const char *str2 = (pa2==pb2) ? "yes" : "no";
printf("%s %s\n", str1, str2);
return 0;
}
你能预测程序的结果吗? 是 "yes yes" 还是 "yes no", 抑或其它值?
有些牛人可能会说结果依赖于编译器, 那让我问得更具体些:
用Visual C++编译后结果如何, 在C++ Builder中又怎样呢?