RH>Hello Tim ...
Howdy, Rene...
TH>constructor (no args) is not specified in your code, the compiler
TH>will create one for you. That's why there was no error.
RH>But now you're confusing me again. Not only was there no
RH>error, but declaring a TTime object as "TTime Time;" really
RH>resulted in the compiler calling my constructor with all
RH>arguments set to -1, not in calling an automatically
RH>generated no argument constructor.
When the compiler generated the object "Time" the default constructor
is called,... Hmmm, that's a misnomer, since I don't think any code
is generated. Space is set aside for the object(s), but they are not
initialized. Look at it as a compile time event, but it does affect
code generation. Anyway, whatever happens to be in RAM (usually in
the hardware stack space) at the time will be what you start with.
RH>Furthermore, why must every class have a default constructor?
Because a class is a data structure like a 'struct', but with the
added feature of having methods (functions) to give the object (the
variables) functionality. The constructor creates these objects, and
without them you got no class... Er, ah.. you know what I mean. [grin]
RH>When I never declare an object of the class without explicitly
RH>stating which constructor to use (ie only declare a TTime Time(1,
RH>1, 1980, 0, 0);) there is no use for a default constructor, is
RH>there?
Sure there is. Objects may be created before you know what has to go
in them. They would be filled in at some later time. This is common
in base classes where the object is inherited by some descendant
class. Here an instance of the base class is needed even though the
data isn't ready, or available for it.
RH>Also, with simple classes that don't declare any virtual
RH>functions, there's really nothing to construct. When I have a
RH>declaring a TClass object doesn't generate any code. For
RH>the following main function
The compiler reserved storage space on the stack as per the default
constructor, but since there is no initialization, there are no
instructions.
RH>[ sidenote: making member function Set virtual, the
RH>compiler *does* indeed insert an (inline) constructor,
RH>initializing the objects VMT pointer:
Virtual functions are treated in a special way.
RH>Or did I get you wrong?
Maybe I'm just misunderstood. [grin]
Always Remember: Reality is a special case... [grin]
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 530-893-8079 * (1:119/88)
|