Re: Confused about non-virtual functions
On Mon, 23 Jun 2003 23:34:51 GMT, Robert William Vesterman
>I'm confused about the purpose of non-virtual functions. As I
>understand it, if you have a class E that extends a class B and
>overrides a non-virtual function f(), then the f() that actually gets
>called for an E object depends upon whether that E object is known as
>an E or as a B at the time of the call.
>I don't understand what's useful about this ambiguity in what the f()
>of an E is. Could someone please give me an example of why it would
>I don't mean "useful as opposed to virtual functions". I mean "useful
>as opposed to not allowing non-virtual functions to be overridden in
>the first place".
>That is, imagine a language C++--, which is identical to C++ except
>that non-virtual functions cannot be overridden. What's an example of
>a case where C++ is more useful, or nicer, or cleaner, or safer, or
>more whatever, than C++--?
There's one case where I've used it - optimization. Basically, the
hiding derived class function has exactly the same behaviour as the
base class function, but uses knowledge of the derived class to
optimize the operation.
Called through the base class pointer it will still work, but if you
call it through a pointer of derived class type, it will run faster.
|All times are GMT. The time now is 03:40 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.