int main() { Man *m = new Man(1, "Man:WuWenhao"); //执行当前类的函数 //若派生类与基类有相同的函数,则运行派生类的函数,否则运行基类的函数 m->sayHello(); //执行父级函数 m->People::sayHello(); People *p1 = new Man(); p1->sayHello(); m->Eat(); p1->Eat(); p1->Sleep(); int age = m->getAge(); int sex = m->getSex(); char *name = m->getName(); delete m; delete p1; return 0; }
int main() { Man *m = new Man(21); m->sayHello(); m->People::sayHello(); return 0; }
int main(int argc, const char * argv[]) { Man *man = new Man(21); man->sayHello(); man->People::sayHello(); beiluo::People * p = new Man(21); p->sayHello(); p->People::sayHello(); ((Man*)p)->sayHello(); return 0; }
int main(int argc, const char * argv[]) { Man *m = new Man(20); m->sayHello(); return 0; }