Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!sorensen From: sorensen@athena.mit.edu (Alma G. Sorensen) Newsgroups: comp.lang.c++ Subject: changing what a virtual function returns Summary: How can I do this? Message-ID: <12057@bloom-beacon.MIT.EDU> Date: 17 Jun 89 19:06:20 GMT Sender: daemon@bloom-beacon.MIT.EDU Reply-To: sorensen@imager.mit.edu (Greg Sorensen) Organization: Massachusetts Institute of Technology Lines: 49 I have a base class for containing arrays, like: class base { private: int length; void * base; public base(void * start,int size){ base = start; length = size;} }; and a derived classes for either, say, integers or floats: class ints : public base { ints(int * start, int size):(start,size){;} } class floats : public base { floats(float * start, int size) : (start, size) {;} } and I'd like to add the operator [] to my base class, so that I can access a base using [] without having to worry too much about the fundamental type, e.g.: virtual void& operator[](int index) = 0; in the base class, and something like int& operator[](int index) { return (base + length); } in the ints class, and a similar construct for the floats class. But, of course, there is no such legal type as void&, and I can't figure out what the reference equivalent of void* is...What can I do? Must I have some class which is either an int or a float and return a reference to that? Thanks, Greg Sorensen sorensen@imager.mit.edu or sorensen@athena.mit.edu