Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!atha!aunro!ukma!dftsrv!mimsy!midway!iitmax!chien From: chien@iitmax.iit.edu (Greg Chien) Newsgroups: comp.lang.c++ Subject: HELP: default constructor for array of class Keywords: constructor, default, class, array, definition Message-ID: <1991May2.165955.28385@iitmax.iit.edu> Date: 2 May 91 16:59:55 GMT Organization: Illinois Institute of Technology / Academic Computing Center Lines: 36 A beginner's question to C++ gurus: When compiling the following program, C++ complains that Point::Point() default constructor is not found in resolving Point p[2]. However, if Point() { x = 200; } is uncommented, ambiguous constructors error is generated in resolving Point q. Both cases are tried with HP/C++ 2.1 and Borland C++. What should be the right way to do? Thanks in advance. Greg Chien Design Processes Laboratory Institute of Design Illinois Institute of Technology chien@iitmax.iit.edu // ---------------- 8< -------- CUT HERE ---------- 8< ----------------- #include class Point { int x; public: // Point() { x = 200; } Point(int xc = 100) { x = xc; } GetX() { return x;} }; int main() { Point p[2]; Point q; cout << p[1].GetX() << "\n"; cout << q.GetX() << "\nO.K.\n"; return 0; } // ---------------- 8< -------- CUT HERE ---------- 8< -----------------