/* ( n8.C ) NIHクラス・ライブラリを使う−その2 ユ−ザ定義したクラスをNIHクラス(例:Linkedlist)で使う ための最低限の実装に、printOn だけ使えるようにした。 */ #include "Object.h" //------ << Circle.h >> -------------- class Circle: public VIRTUAL Object { int rad,x,y; public: Circle( int a,int b, int r) { x=a; y=b; rad=r; } private: DECLARE_MEMBERS(Circle); protected: void storer(OIOofd&) const {} void storer(OIOout&) const {} public: void deepenShallowCopy() {} unsigned hash() const { return 0; } bool isEqual(const Object&) const { return 0; } int compare(const Object&) const { return 0;} void printOn(ostream& strm=cout) const ; const Class* species() const { return &classDesc; } }; //#include "Circle.h" //------ << Circle.C >> -------------- //#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); void Circle::printOn(ostream& strm) const { strm << '(' << x << ',' << y << ',' << rad << ')'; } Circle::Circle(OIOifd& fd) : BASE(fd) { fd >> x >> y; } Circle::Circle(OIOin& strm) : BASE(strm) { strm >> x >> y; } #include "LinkedList.h" //------ << main program >> ---------- #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.printOn( cout ) ; // cout << "b = " << b << endl でもよい cout << endl; b.removeAll(); } /* [結果] 使うのにこんなにめんどうなのか、本当かな−。 (1,1,1) もっと簡単に使う方法はないのか? (2,2,2) (3,3,3) */