Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ut-emx!walt.cc.utexas.edu!ycy From: ycy@walt.cc.utexas.edu (Joseph Yip) Newsgroups: comp.lang.c++ Subject: char, int, float array object operations Message-ID: <20838@ut-emx.UUCP> Date: 13 Nov 89 08:07:01 GMT Sender: news@ut-emx.UUCP Reply-To: ycy@walt.cc.utexas.edu (Joseph Yip) Organization: The University of Texas at Austin, Austin, Texas Lines: 49 I am trying to write some C++ routines to handle array operations. For example, A = B + C adds arrays B and C and assigned to A. The declaration may be : class Array_char { public: Array_char(int r, int c); Array_char& operator+(Array_char&); // addition Array_char& operator*(Array_char&); // multi. Array_char& operator=(Array_char&); // assignment ... private: char *p; // char array (1D or 2D) int row,col; }; My C++ routines should be able to handle integer and floating arithematics. To allow, say floating point, an other kind of data type operation, do I have to declare a class? i.e. class Array_float { ... Array_float& operator+(Array_float&); // addition ... private: float *p; // pointer to float array int row,col; }; The operation on char array is the same as those on float or integer array. Is there any way to use code that is written for char? I was thinking about derivation and void pointer. I may be able to make a base class that contains all the array operations and defines Array_char, Array_int, and Array_float clases to inherit the base class. This requires that the array pointer in the base class needs to be defined as void*. Because of void*, I need to declare some virtual functions. It is because we cannot work with void*. To use void*, we need to explicitly cast it to some type. So, to add two characters values, we need, virtual void* add(void*, void*); Also, one may need to do, A = B + C, where B is a character array and C is a floating array and A is a character array. This means we need to do user-defined conversion! What a mess! Any advice or insights on doing these kind of object-oriented programming? Joseph