Tuesday, June 26, 2007

Never redefine a function's inherited default parameter value

Virtual functions are dynamically bound whereas default parameter values are statically bound

I wonder why compilers cannot check for this case themselves ?

How will this interact with the case where you don't know the number of arguments beforehand ..not sure even If that is an issue ?

You can use the nvi idiom, , public non  virtual specifies the default argument and then each private virtual can have its argument. Then it is clear and no redefinition happens in derived  Not sure what the author means here ?

Things to remember:
Never redefine an inherited parameter value, because default parameter values are statically bound, while virtual functions --the only functions you should be redefining -- are dynamically bound

No comments: