Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!mcsun!unido!ztivax!athen!are From: are@sinix.UUCP (Andreas Eder) Newsgroups: comp.lang.c++ Subject: beginners question Message-ID: <1991Jun5.090228.27147@sinix.UUCP> Date: 5 Jun 91 09:02:28 GMT Article-I.D.: sinix.1991Jun5.090228.27147 Sender: are@portland.sp4n1.siemens.de Organization: SNI AG Muenchen, STO XS Lines: 19 Hello experts, I'm new to C++ and have the following problem: I have several numeric types such as integers, rationals, reals etc. Now I want a procedure to add to numbers that can add two numbers regardless of the actual type. That is in some place of the code I have number *a, *b; where number is the base type of all the integers, rationals, etc.. Now I want a function number *add(number *, number *) that can add any two numbers. I now about virtual functions, but wouldn't that only work depending on the type of the first variable. Now, how do I do this without switching on the type of the second parameter ? Or do I have to include a type field in the class definition? Any help is welcome. Thank you, Andreas are@portland.sp4n1.siemens.de