In Java it's quite common to call one constructor from another one in
the same objects. Can that be done in C++? Is the same kind of
situation handled in C++ with default values for arguments to the
constructor rather than having two different constructors?
Yes. In general the base class constructor is called implicitly, but you
can also call it explicitly.
class foo {
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Fri, 27 Feb 2004 06:55:29 -0500
"Steven T. Hatton" wrote:
public:
foo() {}
foo(const string &s): _name(s) {}
private:
string _name;
};
class foobar : public foo {
public:
foobar() {} // foo() invoked implicitly.
foobar(const string &s): foo(s) {} // foo is invoked explicitly
}
- --
Jerry Feldman
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQFAP3Di+wA+1cUGHqkRAvy2AJ4uHDB2GmGJzI72vf9fApMkvpmoJACghJK/
AgTQaNRo5fDDBlueoYQ0DaI=
=BP8f
-----END PGP SIGNATURE-----