Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!bonnie.ics.uci.edu!schmidt From: schmidt@bonnie.ics.uci.edu (Douglas C. Schmidt) Newsgroups: comp.lang.c++ Subject: Default initializations for class constructors Keywords: c++ Message-ID: <684@paris.ICS.UCI.EDU> Date: 9 Sep 88 18:59:28 GMT Sender: news@paris.ics.uci.edu Reply-To: schmidt@bonnie.ics.uci.edu (Douglas C. Schmidt) Organization: University of California, Irvine - Dept. of ICS Lines: 54 Hi, Can someone please enlighten me as to the correct behavior of C++ when class constructors with different argument types are all declared to have default parameter initializers? My basic question is, which of the constructors should be selected if the type is not clear from the definition of a class object? G++ appears to use the first lexically presented constructor as the default, is this specified, or is the behavior undefined in the language? The following is a short example illustrating my question: ---------------------------------------- #include class foo { int i; public: foo(double j = 10.5) { i = int(j) * 5; cout << "double constructor\n"; } foo(int j = 10) { i = j; cout << "int constructor\n"; } int Tell() { return i; } }; class bar : public foo { int i; public: bar(void) { i = foo::Tell(); } int Tell(void) { return i; } }; main() { bar Foo; cout << Foo.Tell() << "\n"; // G++ prints out 50 at this point, indicating that it called // the double constructor as default. } thanks for any help on this matter, Doug Schmidt -- schmidt@bonnie.ics.uci.edu (ARPA)