Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!cs.utexas.edu!sun-barr!newstop!exodus!caterina.Eng.Sun.COM!mohans From: mohans@caterina.Eng.Sun.COM (Ram Mohan Srinivasan) Newsgroups: comp.lang.c++ Subject: Question regarding multiple inheritance and virtual functions.. Message-ID: <10614@exodus.Eng.Sun.COM> Date: 28 Mar 91 03:26:21 GMT Sender: news@exodus.Eng.Sun.COM Lines: 82 I took a class in c++ and in doing one of the assignments, I came across the following problem.. I don't know what I'm doing wrong or whether this is the way things are supposed to work.. Can someone explain this to me ? Before U flame me for asking a dumb question - I am a novice c++ pgrmr - And that's my excuse :-) I have the following class declarations : class employee { int emp_no; char *emp_name; public: employee(); ~employee(); virtual void print(); }; class employee_pl_addr : public employee { char *address; public : employee_pl_addr(); ~employee_pl_addr(); void print(); }; class home_addr { char *address; char *tel_no; public : home_addr(); ~home_addr(); virtual void print(); }; class home_and_work : public home_addr, public employee_pl_addr { public : home_and_work() {} ~home_and_work() {} }; #Irrelevent stuff deleted.. # #The print() function in each class, just prints the members.. In my main program, I am trying to get at the virtual function print thus : home_and_work emp; ((employee *) &emp)->print(); ((employee_pl_addr *) &emp)->print(); ((home_addr *) &emp)->print(); The problem that I have is - I do not seem to be able to get at the class employee's print virtual function by ((employee *) &emp)->print(); instead, this calls the print() function of the class employee_pl_addr ! Has this something to do with class scopes ? I was under the impression that we could statically determine which virtual function is to be called in all the 3 above cases.. The examples given in my text call virtual functions this way. Or is it that we can get at virtual functions just one level up ? Oh, and I am using the C++ translator on SunOS 4.1.. thanks, Mohan Srinivasan. mohans@sun.com -- =============================================================================== Ram Mohan Srinivasan (415)-336-1272 (W)