TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: RENE HERMAN
from: DARIN MCBRIDE
date: 1998-04-20 18:43:00
subject: Default constructor

 RH> According to ANSI C++, will a constructor with nothing 
 RH> but default arguments do as a default constructor? I'm 
 RH> learning C++, and my textbook (Mastering Borland C++ 5 
 RH> by Tom Swan) declares a TTime class providing two 
 RH> constructors:
A quick paraphrase of my understanding of default constructor is one that 
does not require any explicit arguments.  That is, if you can create an 
object of type foo as foo f, the constructor called is the default 
constructor.
Now, in practical terms, this means that there are two types of default 
constructors:
  - those with no actual arguments, and
  - those with all default arguments.
[code deleted]
 RH> When I however add a "-1" default argument for "m" in 
 RH> the second constructor and delete the first 
 RH> constructor, Borland 5 doesn't seem to have a problem 
 RH> recognizing it as a default constructor. That is, 
 RH> "TTime Time;" and "TTime Time[SIZE];" compile just 
 RH> fine, calling TTime(-1, -1, -1, -1, -1) as their 
 RH> constructor.
Right.  This is how it should be.
 RH> I am aware that if the constructors weren't inlined 
 RH> different code would be produced for declaring a TTime 
 RH> instance, but the above looks as if the author wanted 
If the book is calling this an "instance", mentally switch it to "object".  
I've found that, personally, terminology has made the switch to object 
orientation much easier to grasp.  By realizing that this object encapsulates 
a real object (in this case, an abstract object that I mistakenly believe I 
understand ), I've made my switch to clean (I think ) OO code.  Without 
the "right" terminology, technical people like ourselves could get confused 
both in understanding the concepts and how to apply them, but also in 
communicating with other technical people.
TTime object;
TTime array_of_objects[SIZE];
 RH> to emphasize that one really needs a constructor 
 RH> without any arguments, not even default ones, as a 
 RH> default constructor. Unfortunately, he doesn't explain 
 RH> any further.
I suspect, instead, that the author was trying to not confuse issues - he 
probably assumes that you may not be ready to make that jump yet in his book.
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.