有以下程序
#include<iostream> using namespace std; class P { char nameP[30]; public: P(const char* name = "123") { strcpy(nameP, name); } const char* getName() { return nameP; } virtual const char* getType() { return "P"; } }; class B :public P { char nameB[30]; public: B(const char* n1, const char* n2) : P(n1) { strcpy(nameB, n2); } const char* getName() { return nameB; } const char* getType() { return "B"; } }; void showP(P* p) { cout << p->getType() << ":" << p->getName() << endl; } int main() { B b("book1", "book2"); showP(&b); return 0; }
程序运行后的结果是()