#include <iostream>
#include<iostream>
using namespace std;
class A
{
public:
void foo()
{
printf("1\n");
}
virtual void fun()
{
printf("2\n");
}
};
class B : public A
{
public:
void foo()
{
printf("3\n");
}
void fun()
{
printf("4\n");
}
void testB()
{
printf("testB\n");
}
};
int main(int argc, const char * argv[]) {
A a;
B *ptr = (B *)&a;
ptr->foo();
ptr->fun();
ptr->testB();
B bb;
A *aa = &bb;
aa->foo();
aa->fun();
return 0;
}
A a;
B *ptr = (B *)&a;
ptr->foo();
ptr->fun();
ptr->testB();
派生类的对象B并没有创建??
为什么能够使用,
多态是怎么调用的