C++子类调用父类覆盖的函数
/*
* main.cpp
* C++子类调用父类覆盖的函数
*/
#include <stdio.h>
class base
{
public:
base(){}
~base(){}
virtual void print() {printf("i'm base!\n");}
};
class child : public base
{
public:
virtual void print(){ base::print(); printf("i'm child!\n");}
};
int main()
{
child p;
p.print();
return 0;
}
/*
* main.cpp
* C++子类调用父类覆盖的函数
*/
#include <stdio.h>
class base
{
public:
base(){}
~base(){}
virtual void print() {printf("i'm base!\n");}
};
class child : public base
{
public:
virtual void print(){ base::print(); printf("i'm child!\n");}
};
int main()
{
child p;
p.print();
return 0;
}