hoelling@tuhold (Wolfgang Hoellinger) (09/19/88)
Does anybody outside in the C++-world know the solution for my problem: class base { .. public: virtual void f1(); virtual void f1(int); }; class derived: public base { .. public: void f1(); /* no definition of f1(int) in this class */ } The Compiler (AT&T C++ Translator, release 1.2 Sun-Wk.1) does not accept this definition -> > sorry, not implemented: virtual derived::f1() overloaded in base class but not in derived class My questions are: Is there any way to define an overloaded virtual function? Is this a problem of C++ or just a problem of my compiler? Wolfgang Hoellinger Technical University of VIENNA, AUSTRIA hoelling@tuhold.uucp mcvax!tuvie!tuhold!hoelling
morrison@eecs.nwu.edu (Vance Morrison) (09/21/88)
Hello, It seems your problem is that you want to overload a virtual function in the base class, but not define all the overloaded function in the derived class. A quick solution to your problem would be to define the overloaded function in the derived class explicitly. class base { .. public: virtual void f1(); virtual void f1(int); }; class derived: public base { .. public: void f1(); void f1(int i) { base::f1(int i); }; } Note that if this is not the behavior that you want, you should probably rethink why exactly you want to do this. Essentially overloading is ONLY for notational convience, if you are trying to use it for something else, you are probably trying to make it do too much. Vance Morrison Northwestern Univ.
turner@sdti.UUCP (Prescott K. Turner) (10/27/88)
In article <1215@tuhold>, hoelling@tuhold (Wolfgang Hoellinger) writes: > > sorry, not implemented: virtual derived::f1() overloaded in base > class but not in derived class > > Is there any way to define an overloaded virtual function? > Is this a problem of C++ or just a problem of my compiler? Yes, it is OK to define an overloaded virtual function. My copy of cfront gives the same message in response to your program. The program will compile OK if void f1(int); is defined in class 'derived'. The warning relates to the fact that redefining any 'f1' in a derived class suppresses all variants of 'f1' from the base class. Amazingly, while this feature operates on all variants simultaneously, the virtual aspect of a member function operates on each variant individually. -- Prescott K. Turner, Jr. Software Development Technologies, Inc. 375 Dutton Rd., Sudbury, MA 01776 USA (508) 443-5779 UUCP:...genrad!mrst!sdti!turner