Article View: gnu.g++
Article #123Re: initialization question
From: Olaf Zurth
Date: Tue, 12 Sep 1989 14:31
Date: Tue, 12 Sep 1989 14:31
33 lines
1573 bytes
1573 bytes
In article <QYzIoRy00iQJM8JkZb@andrew.cmu.edu> 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 |
Technical Details
Message-ID:
<822@astbe.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!mcsun!unido!tub!astbe!zuReferences:
<QYzIoRy00iQJM8JkZb@andrew.cmu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <QYzIoRy00iQJM8JkZb@andrew.cmu.edu> Reply-To: zu@astbe.UUCP (Olaf Zurth) Organization: GEI Software Technik Berlin, Germany Lines: 33