// file: lecture_27/myprog.h // // system include files // #include #include // define a simple class // class Toaster { protected: // define some data // char* name_d; char* model_d; long len_d; long width_d; float weight_d; // define some simple functions // public: // default constructor // Toaster() { // initialize data // name_d = (char*)NULL; model_d = (char*)NULL; len_d = (long)0; width_d = (long)0; weight_d = (float)0; // display some information about the object // fprintf(stdout, "Default Constructor: len_d is located at %u\n", &len_d); fprintf(stdout, "Default Constructor: width_d is located at %u\n", &width_d); } // default destructor // ~Toaster() { fprintf(stdout, "Default Destructor: cleaning up memory!\n"); if (name_d != (char*)NULL) { delete [] name_d; name_d = (char*)NULL; } if (model_d != (char*)NULL) { delete [] model_d; model_d = (char*)NULL; } } // implement some inline functions // long get_len() { return len_d; } //long get_len(char* str = (char*)NULL) { // fprintf(stdout, "... here I am ...\n"); //Toaster tmp; //return (long)-1; //} long get_width() { return width_d; } float get_weight() { return weight_d; } // define some useful public functions // bool display(FILE* fp, char* object_name = (char*)NULL); bool display(Toaster& tst) { tst.display(stdout, (char*)"tst"); return true; } bool set_values(long len, long width, float weight); // demonstrate an overloaded function // bool compare(Toaster arg1); bool compare(Toaster* arg1); bool compare(Toaster& arg1); private: // print the data of manufacturing // //bool display(FILE* fp); // end of class };