Xref: utzoo gnu.g++:382 comp.lang.c++:4656 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!mcsun!unido!tub!astbe!zu From: zu@astbe.UUCP (Olaf Zurth) Newsgroups: gnu.g++,comp.lang.c++ Subject: Re: initialization question Message-ID: <822@astbe.UUCP> Date: 12 Sep 89 14:31:17 GMT References: Reply-To: zu@astbe.UUCP (Olaf Zurth) Organization: GEI Software Technik Berlin, Germany Lines: 33 In article ct13+@andrew.cmu.edu (Chris Thewalt) writes: >if I have a class X, and a constructor X(X&) defined, and abc is an >instance of X,then > X a = abc >works as described in the book. >However, if I have abc and def as instances of X, and operator + defined >as: X& operator+(X&, X&), then the following: > X a = abc + def >does not call the constructor when creating a (I get bitwise copy of result). >Is this behavior correct? >[note: using GNU g++ version 1.35] You have an assigment and therefor you need an operator=(X&) for your class. Bitwise copy is default for assigment. The best way is to build "save classes", which looks like class X { // some stuff X(something); X(X&); operator=(X&); ~X(); }; --Olaf Zurth [see Stroustrup, p.180] -- | Olaf Zurth GEI Software Technik Berlin Abt. A93-E2 | | Hohenzollerndamm 150 D 1000 Berlin 33 Tel. (voice): +30 828 2892 | | UUCP: zu@astbe.UUCP olaf%zubln@astbe.UUCP BITNET: zu%astbe@db0tui6.BITNET |