#include <assert.h> #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Subject { public: virtual string Name() = 0; }; class Calculus : public Subject { public: string Name() { return "Calculus"; } }; class English : public Subject { public: string Name() { return "English"; } }; class Algebra : public Subject { public: string Name() { return "Algebra"; } }; class Cpp : public Subject { public: string Name() { return "C++ Language"; } }; class Physics : public Subject { public: string Name() { return "Physics"; } }; void fillObjects(Subject *o[]) { o[0] = new Calculus; o[1] = new English; o[2] = new Algebra; o[3] = new Cpp; o[4] = new Physics; } int main() { Subject *o[5]; fillObjects(o); assert(o[0]->Name() == "Calculus"); assert(o[1]->Name() == "English"); assert(o[2]->Name() == "Algebra"); assert(o[3]->Name() == "C++ Language"); assert(o[4]->Name() == "Physics"); cout << "pass!!!" << endl; for (int i = 0; i < 5; i++) delete o[i]; return 0; }
点赞 评论

相关推荐

哞客37422655...:这就是真实社会,没有花里胡哨的安慰,让你感受到阶级分明,不浪费彼此时间。虽然露骨但是唉
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务