/* ( n7.C ) NIHクラス・ライブラリを使う−その1 ユ−ザ定義したクラスをNIHクラス(例:Linkedlist)で使う ための最低限の実装。 */ //------ << Circle.h >> ----------------------------------------- #include "Object.h" // Object.h をインクル−ドする class Circle: public VIRTUAL Object { // NIHCL の派生クラスとする int rad,x,y; public: Circle( int a,int b, int r) { x=a; y=b; rad=r; } private: // ここから下は、ともかく必要 DECLARE_MEMBERS(Circle); // virtual の宣言はなくてもよい protected: virtual void storer(OIOofd&) const {} virtual void storer(OIOout&) const {} public: virtual void deepenShallowCopy() {} virtual unsigned hash() const { return 0; } virtual bool isEqual(const Object&) const { return 0; } virtual int compare(const Object&) const { return 0;} virtual void printOn(ostream&) const {} virtual const Class* species() const { return &classDesc; } }; //------ << Circle.C >> ----------------------------------------- //#include "Circle.h" // ここから下も、ともかく必要 #include "nihclIO.h" /* これをインクル−ドするとワ−ニングが出てくる */ #define THIS Circle #define BASE Object #define BASE_CLASSES Object::desc() #define MEMBER_CLASSES #define VIRTUAL_BASE_CLASSES DEFINE_CLASS(Circle,1,"",NULL,NULL); // 何か適当に入れておく Circle::Circle(OIOin& strm): BASE(strm) { strm >> x >> y; } Circle::Circle(OIOifd& fd): BASE(fd) { fd >> x >> y; } //------ << main program >> ------------------------------------- #include "LinkedList.h" #include "LinkOb.h" main() { Circle A(1,1,1); Circle B(2,2,2); Circle C(3,3,3); LinkOb bA(A); LinkOb bB(B); LinkOb bC(C); LinkedList b ; b.add(bA); b.add(bB); b.add(bC); b.removeAll(); }