🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Chris Thewalt Thu, 31 Aug 1989 15:22
initialization question
#98
Author: Chris Thewalt
Date: Thu, 31 Aug 1989 15:22
12 lines
851 bytes
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]

thewalt@ce.cmu.edu
Re: initialization question
#123
Author: Olaf Zurth
Date: Tue, 12 Sep 1989 14:31
33 lines
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 |
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads