From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,b87849933931bc93 X-Google-Attributes: gidf43e6,public X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public From: doylep@ecf.toronto.edu (Patrick Doyle) Subject: Re: What is wrong with OO ? Date: 1997/01/16 Message-ID: #1/1 X-Deja-AN: 210242665 x-nntp-posting-host: spark27.ecf sender: news@ecf.toronto.edu (News Administrator) references: <01bbd23a$5b667cc0$LocalHost@christophe-leph> <01bc03db$2de477c0$ba1e1990@ap352pc.us.oracle.com> organization: University of Toronto, Engineering Computing Facility newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object,comp.software-eng Date: 1997-01-16T00:00:00+00:00 List-Id: In article <01bc03db$2de477c0$ba1e1990@ap352pc.us.oracle.com>, Risto Lankinen wrote: > >Patrick Doyle wrote in article >... >> >> Suppose a function does some important manipulation of private data >> members. If it were virtual, then an heir class could override this >> function without ever calling it, and the data manipulation would never >> happen. This could leave the object in an invalid state. In C++, the >> only way to prevent this is by NOT declaring the function virtual. > >This is true. I would like to add, that if *both* the important data >manipulation *and* virtualness are needed, then there is still a way >to do it. Here's how: > >-------------------------------------------------- >class Base >{ >private: > virtual void Function_imp() I was not aware that private virtual functions existed. Can a descendant class override this function even though it does not have access to it? >Note that *IF* the Java keyword 'final' was also in C++ (in Java >it means that a member function cannot be overridden, or a class >cannot be derived) then in the example, 'Base::Function()' could >itself be a virtual function derived from yet-another-base, but >then overridden and declared as 'final'. Obviously this would >make it possible to stack postcondition checks by doing the same >'final'-trick to 'Derived::Function_imp()' and have it call, say, >private virtual 'Function_imp_imp()' that *its* derived classes >can override... Woah, sorry, you lost me here. Do you have an example of what you're thinking of? -- -- Patrick Doyle doylep@ecf.utoronto.ca