[comp.lang.c++] changing what a virtual function returns

sorensen@athena.mit.edu (Alma G. Sorensen) (07/23/89)

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