Hello Darin ...
Monday April 20 1998, you wrote Rene Herman
RH>> According to ANSI C++, will a constructor with nothing
RH>> but default arguments do as a default constructor?
DM> A quick paraphrase of my understanding of default constructor is one
DM> that does not require any explicit arguments.
Thanks. Does indeed seem the most logical thing. Book got me confused when it
so explicitly declared a constructor without any arguments while simply
adding an extra default argument to the other constructor made it
functionally equivalent.
DM> If the book is calling this an "instance", mentally switch it to
DM> "object".
Now that you mention it, it actually uses "object", don't know why I called
it an instance. In fact, I'm not all to sure when and why to call anything an
instance. Not having English as my native language, most of the terminology
is quite literally foreign to me anyway. Now that you got me interested,
under what circumstances *would* instance be proper terminology? An instance
of a template?
DM> I've found that, personally, terminology has made the switch to
DM> object orientation much easier to grasp.
Fortunately, I'm not completely new to object orientation, having used OOP
principles with Borland Pascal. Mostly in using the Turbo Vision framework
though, building my own class hierarchies remains somewhat of a black art.
Furthermore, C++ classes are rather more mature than Pascal objects were
before Delphi came along, so much left to learn...
DM> By realizing that this object encapsulates a real object (in this
DM> case, an abstract object that I mistakenly believe I understand ),
DM> I've made my switch to clean (I think ) OO code.
I object!
DM> Without the "right" terminology, technical people like ourselves
DM> could get confused both in understanding the concepts and how to
DM> apply them, but also in communicating with other technical people.
Yet you seem to have managed to confuse me quite nicely in your last
paragraph using the *right* terminology. This object encapsulates a real
object? Which object? What's a real object and why is it encapsulated? Where
do abstract objects come into this? Please elaborate. :-)
DM> I suspect, instead, that the author was trying to not confuse issues
And still, he did. Thanks for the answer. You probably shouldn't have replied
though, because now I will no doubt continue to bother you with all kinds of
dumb questions. Have some "stylish" ones for you right now.
In both C and C++ main always seems to come first, with the functions it uses
prototyped above it, and implemented below. Coming from Pascal, I always put
main last, with everything implemented in full above it. Am I offending
(m)any people?
I believe I remember reading, in this echo, a while back that the C++ style
for functions which don't take any arguments is "empty parenthesis", as
opposed to the "void" keyword? That is, which is generally preffered, int
main(void) or int main()?
If the void keyword is fine, does that also go for default constructors and
destructors? Tom Swan never uses "void" in constructors and destructors, does
use it in member functions, and doesn't use it for main.
I believe reading that in C++ the macro NULL and a literal zero are
guaranteed the same? Is either strongly preferred? Don't much care for NULL.
When implementing member functions inline in the class declaration, the
consensus seems to be to cram it all on a single line. Is it considered bad
style to spread it out some more? Ie:
class TExample {
private:
char *s;
public:
TExample(void) // or TExample() ?
{
s = 0; // or NULL ?
}
I hate thinking up new names all the time. Is the following, using the this
pointer for scope resolution, okay?
TExample(char *s)
{
this->s = strdup(s);
}
The book warns against not mixing C and C++ memory allocation features, yet
it keeps doing things like:
~TExample(void) // or ~TExample() ?
{
delete s;
}
while s was allocated memory through strdup, which if I am not mistaken calls
malloc. Should it? Even if it should or may, shouldn't it rather use
delete[], since s is pointing not to just one char, but to an array of chars?
Last, would you happen to know if/where one might obtain a copy of the
(draft) ANSI C++ standard? I remember reading that question in here before,
but I never saved an answer (if there was any).
Thanks in advance for any answers you might provide. Hope I didn't ask too
many questions at once. Please be aware that if you do reply I will very
likely have some more lined up for you by that time... :-)
Rene
---
---------------
* Origin: postmaster@rene.demon.nl (2:282/1.11)
|