[comp.lang.c++] Return values of virtual functions

cwang@tut.cis.ohio-state.edu (Chang-Jia Wang) (02/26/90)

I was using Zortech C++.

How can I have instances of a virtual function in a base class return
different type of values?  For example, suppose there are two classes of
matrices, IntMat and FloatMat, which are derived from a base class, Matrix.
A member function called Element(i,j) returns an element in a matrix.  The
function should return an int& in IntMat, but return a float& in FloatMat.

I cannot define a virtual function in Matrix because a virtual function
must return the same type of value as its derived classes do.  What tricks
should I use in order to call Matrix::Element(i,j), so a proper type of
value can be returned?

C.J.