class num_sequence
{
public:
num_sequence(void){};
virtual const char* what_am_i() const { return "num_sequence \n"; } //注意这里的两个const
virtual ~num_sequence(void){};
};
class Fibonacci :
public num_sequence
{
public:
Fibonacci(void){};
const char* what_am_i() const { return "Fibonacci \n"; } //同样注意这里的两个const,少哪个都不行,
~Fibonacci(void){};
};
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Fibonacci b;
num_sequence p;
num_sequence *pp = &b;
cout << pp->what_am_i();//输出Fibonacci
cout << b.what_am_i();//输出 Fibonacci
int tem;
cin >> tem;
return 0;
}