Re: Making class-typed method parameters optional without overloading?
On 6/12/2014 11:54 AM, Matt Gregory wrote:
On Thursday, June 12, 2014 11:21:37 AM UTC-4, Wouter van Ooijen wrote:
Maybe think like this: if the user doesn't supply StartDate and EndDate,
what dates would you use? If fixed dates, you can supply those as
defaults. If not, can you think of some impossible date value that you
can specify as default and test for in the body?
I thought I might define a const TDateTime NODATE; constant in the
class, so the caller could use TJDBCustRewardTable::NODATE in order to
bypass those parameters, but if TDateTime requires a constructor???
class Example1
{
public:
Example1(int value);
static const Example1 NOTHING;
};
const Example1 Example1::NOTHING(42);
void foo(Example1 something = Example1::NOTHING)
{
if (something == Example1::NOTHING) ... // requires op== defined
}
int main()
{
foo(Example1(73));
foo(); // using default value
}
From what I remember about C++, it can't be done. But maybe a newer
standard makes it possible nowadays?
What can't be done? Be a bit more specific.
V
--
I do not respond to top-posted replies, please don't ask