2
#ifndef FRABJOUS_H_ #define FRABJOUS_H_ #include <iostream> #include <string> class Frabjous { private: std::string fab; public: Frabjous(const char *s = "C++") :fab(s) {} virtual void tell() { std::cout << fab; } }; class Gloam { private: int glip; Frabjous fb; public: Gloam(int g = 0, const char *s = "C++") :glip(g), fb(s) {} Gloam(int g, const Frabjous &f) :glip(g), fb(f) {} void tell(); }; #endif
#include "frabjous.h" void Gloam::tell() { fb.tell(); std::cout << " " << glip << std::endl; }
3
#include <iostream> #include <string> class Frabjous { private: std::string fab; public: Frabjous(const char *s = "C++") :fab(s) {} virtual void tell() { std::cout << fab; } }; class Gloam :private Frabjous { private: int glip; public: Gloam(int g = 0, const char *s = "C++") :glip(g), Frabjous(s) {} Gloam(int g, const Frabjous &f) :glip(g), Frabjous(f) {} void tell(); }; void Gloam::tell() { Frabjous::tell(); std::cout << " " << glip << std::endl; } int main() { Gloam p1(24, "神秘"); p1.tell(); system("pause"); return 0; }
4
class Stack<Worker *> { private: enum { MAX = 10 }; Worker * items[MAX]; int top; public: Stack(); bool isempty(); bool isfull(); bool push(const Worker * & item); bool pop(Worker * & item); };