// $Id: skeleton.h,v 1.1 2005/11/16 20:18:08 sms Exp $ // www.pccl.demon.co.uk // // A skeleton class declaration. // References: // 1. Effective C++. Second Edition. // Scott Meyers. // ISBN: 0-201-92488 // // 2. The C++ Programming Language // Bjarne Stroustrup. // ISBN: 0-201-53992-6 // #include // No .h (Ref 1 Item 2) class CCCCC: public BBBBB { public: // Constructors. // Initialisation List // initialise all pointers (to zero) (Ref 1 Item 6, 12). // list members in order declared in class (Ref 1 Item 13). // Default Constructor // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // Used: // CCCCC c1; CCCCC () {}; // Copy constructor. // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // You will need to provide one if dynamic memory is used (Ref 1 Item 11). // Used: // CCCCC c1(c2); // pass by value to function. // return value from function CCCCC (const CCCCC& rhs) { // Assign new dynamic memory and and copy over data (Ref 1 Item 11). } // Destructor // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // You will need to provide one if dynamic memory is used (Ref 1 Item 11). // This should be virtual for Base classes. virtual ~CCCCC () { // Delete all dynamic memory (Ref 1 Item 6). }; // Operators. // Assignment operator. // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // You will need to provide one if dynamic memory is used (Ref 1 Item 11). CCCC& operator= (const CCCCC& rhs) { // Don't copy to self (Ref 1, Item 17). if (this != &rhs) { // Make sure that the base class assigns too (Ref 1 Item 16). BBBBB::operator= (rhs); // Delete existing memory from this and assign new // (Ref 1 Item 6, 11). // Copy data from (non-NULL) pointers into new memory. // Assign all data members (Ref 1 Item 16). } // Returns *this (Ref 1 Item 15). return *this; } // Address of operator (non const). // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // Used: // CCCCC *c1 = &c2; CCCC* operator& () { return (this); } // Address of operator (const). // The system will always provide one so make this private if you don't // want it (Ref 1 Item 27). Remove the function if the default is ok. // Used: // const CCCCC *c1 = &c2; const CCCC* operator& () const { return (this); } // The following operators can be declared (Ref 2 Section 7.2): // + - * / % ^ & | ~ ! // = < > += -= *= /= %= ^= &= // |= << >> >>= <<= == != <= >= && // || ++ -- ->* , -> [] () new delete // NB: CCCC operator++ () is pre-increment. // CCCC operator++ (int) is post-increment. // There should be no public data members (Ref 1 Item 20). private: protected: } // I/O // Declare these in header file. // Define them in a source file // // Input // This is never a class member (Ref 1 Item 19). // Maybe a friend (Ref 1 Item 19). // Maybe use an access function. istream& istream::operator>> (istream& in, CCCCC ccc) { // (Ref 1 Item 19) // Ensure (perhaps by using accesors): // Delete any dynamically allocated data that will be overwritten // Allocate new dynamically allocated data // Read in data and set new values. eg: // in >> newData; // ccc.SetValue (newData); return (*in); } // Output // This is never a class member (Ref 1 Item 19). // Maybe a friend (Ref 1 Item 19). // Maybe use an access function. ostream& ostream::operator<< (ostream& out, CCCCC ccc) { // Extract the data from the object. eg: // out << ccc.printable(); return (*out); }