Re: A few minor questions
* blargg:
You cannot call constructors;
Of course one can, and that's the terminology employed both in practical
programming and by the standard.
the compiler does it as a part of constructing an object.
I think you mean that the compiler generates machine code (or other executable
code such as byte code) that calls a constructor.
And that is partially correct.
A source code constructor call may however not necessarily be translated to an
actual machine code call.
When constructing an object, the compiler never
calls more than one constructor for a given class.
That's literally meaningless, but I think you mean, "the generated machine code"
rather than "the compiler".
And if so then that's very incorrect.
But a correct description of it all, including calls to base class constructors,
the case of virtual inheritance, C++0x constructor call forwarding, and the
whole shebang, would be long.
A constructor cannot be virtual, since it creates an object out of storage
where there was none before.
I'm sorry but that's again incorrect, a misguided rationalization. The reason
that a constructor cannot be declared "virtual" in C++ is because the language
is designed that way. As discussed ad nauseam before it's not at all difficult
to find reasonable and useful semantics for a virtual-declared constructor, and
indeed standard terms such as "virtual constructor" (see the FAQ) wouldn't exist
if such reasonable and practically useful semantics did not exist.
And again, you cannot call a constructor directly;
I'm sorry but that's meaningless.
the compiler does it as a part of constructing an object.
In C++98 the compiler does not call anything in the program being compiled; it
just generates corresponding code (usually machine code).
You
can supply parameters for a base class constructor, which the compiler
calls before executing the body of the derived class consturctor. "derived
class" is the C++ term for subclass, and "base class" for the parent, BTW.
I imagine the C++ FAQ might answer related questions:
<http://www.parashift.com/c++-faq-lite/>
Yes, the FAQ is a good idea. :-)
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!