Re: virtual method hidden
Re: virtual method hidden
- Subject: Re: virtual method hidden
- From: Glen Low <email@hidden>
- Date: Fri, 9 Dec 2005 07:54:31 +0800
All:
On 09/12/2005, at 6:39 AM, Andy O'Meara wrote:
In that it isn't clear if it's calling the base1 method or if it's
calling the base2 method with the default value for the 2nd parm. But
the 2 methods in my previous example have no default values, and it's
really clear that the 2 are quite different.
Yep, no doubt that it's any annoying language spec. Over the years,
whenever I'm in that situation, I do the following:
class Base {
public:
void Foo( void* inPtr ) { Foo_Impl( -1, inPtr ); }
void Foo( int x ) { Foo_Impl( x, NULL ); }
protected:
virtual void Foo_Impl( int x, void* inPtr );
};
class Blah {
protected:
virtual void Foo_Impl( int x, void* inPtr );
};
It's a little more wordy, but it buys you public name overloading
and it
saves you from getting crazy with the 'ol scope operator (making
the code
less pliable). You also don't pick up any overhead since the
compiler will
be smart enough to inline the calls to Foo_Impl. I also like this
trick
because you end up with a 'master' Foo_Impl() fcn with more general/
private
parameters (and the public fcns just do any trivial arg
conversion/substitution such as I have above).
As you've demonstrated, most modern C++ gurus e.g. Herb Sutter say
all of your virtuals should be private/protected and called from
(inline) public methods. Theoretically this is to separate the
separate concerns of "public interface" and "customizability".
Practically it allows you to do things like insert debug or
instrumental or essential code into the public method and still allow
the private method to be overridden correctly.
See http://www.gotw.ca/publications/mill18.htm.
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden