Xref: utzoo comp.lang.c++:7200 gnu.g++:796 Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!apple!agate!e260-2d!c60c-2ca From: c60c-2ca@e260-2d.berkeley.edu (Andrew Choi) Newsgroups: comp.lang.c++,gnu.g++ Subject: Re: Constructing member objects? Message-ID: <1990Apr14.062524.24205@agate.berkeley.edu> Date: 14 Apr 90 06:25:24 GMT References: Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: c60c-2ca@e260-2d (Andrew Choi) Organization: University of California, Berkeley Lines: 41 In article cimshop!davidm@uunet.UU.NET (David S. Masterson) writes: >I'm attempting what I thought was a simple thing, namely constructing an >object that has member objects (in this case - one). The following: > >class A { > ... >public: > A() {...} > ~A() {...} >}; > >class B { > A a; > int x; >public: > B(int n=0):A(n) { x = n; } > ~B() {} >}; > >gets me a "A is not a Base type for B" error from G++ 1.36. Am I using the >right syntax or is this a bug with this compiler? > >-- You are using the wrong syntax. class B should be defined as: class B { A a; int x; public: B(int n = 0) : a(n) { x = n; } ~B() {} }; You use the form you have if and only if B is derived from A. Andrew Choi Internet Address: c60c-2ca@web.berkeley.edu Standard Disclaimer