Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!cwang From: cwang@tut.cis.ohio-state.edu (Chang-Jia Wang) Newsgroups: comp.lang.c++ Subject: Return values of virtual functions Keywords: virtual function Message-ID: <77594@tut.cis.ohio-state.edu> Date: 26 Feb 90 03:24:17 GMT Distribution: na Organization: Ohio State Univ Computer & Info Science Lines: 14 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.