Hello All ...
According to ANSI C++, will a constructor with nothing but default arguments
do as a default constructor? I'm learning C++, and my textbook (Mastering
Borland C++ 5 by Tom Swan) declares a TTime class providing two constructors:
class TTime {
...
public:
TTime()
{
SetTime(-1, -1, -1, -1, -1);
}
TTime(int m, int d = -1, int y = -1, int hr = -1, int min = -1)
{
SetTime(m, d, y, hr, min);
}
...
};
When I however add a "-1" default argument for "m" in the second constructor
and delete the first constructor, Borland 5 doesn't seem to have a problem
recognizing it as a default constructor. That is, "TTime Time;" and "TTime
Time[SIZE];" compile just fine, calling TTime(-1, -1, -1, -1, -1) as their
constructor.
I am aware that if the constructors weren't inlined different code would be
produced for declaring a TTime instance, but the above looks as if the author
wanted to emphasize that one really needs a constructor without any
arguments, not even default ones, as a default constructor. Unfortunately, he
doesn't explain any further.
Rene
---
---------------
* Origin: postmaster@rene.demon.nl (2:282/1.11)
|