🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: de.comp.lang.c++
5 messages
5 total messages Started by Christian Groeling Wed, 03 Apr 1996 21:00
Brauch Hilfe bei Container-Arrays ???
#1985
Author: Christian Groeling
Date: Wed, 03 Apr 1996 21:00
27 lines
1024 bytes
Moin Leute,

ich wollte eigentlich nur erklärt haben warum der unten aufgeführte
Teil eines C++ Listings die Zeile " int operator==(const Position& mc)
const{} " braucht (und warum). Ich weiss es hat irgendetwas mit einem
Copy Konstruktor zu tun. 

class Position
{
	 public  :
			int xz;
			int yz;
			void eingabe(int x,int y) {xz=x;yz=y;}
			Position(){
			xz =0;
			yz =0;
			};
			int operator==(const Position& mc) const{};
};

typedef TArrayAsVector<Position> TRectArray;
typedef TArrayAsVectorIterator<Position> TRectArrayIterator;

Danke schon mal im vorraus !!
          CUL8R  Chris 

Gruss Chris !
Re: Brauch Hilfe bei Container-Arrays ???
#2013
Author: Enno Sandner
Date: Thu, 04 Apr 1996 09:09
40 lines
1911 bytes
Christian Groeling wrote:
> 
> Moin Leute,
> 
> ich wollte eigentlich nur erklärt haben warum der unten aufgeführte
> Teil eines C++ Listings die Zeile " int operator==(const Position& mc)
> const{} " braucht (und warum). Ich weiss es hat irgendetwas mit einem
> Copy Konstruktor zu tun.
> 
> class Position
> {
>          public  :
>                         int xz;
>                         int yz;
>                         void eingabe(int x,int y) {xz=x;yz=y;}
>                         Position(){
>                         xz =0;
>                         yz =0;
>                         };
>                         int operator==(const Position& mc) const{};
> };
> 
> typedef TArrayAsVector<Position> TRectArray;
> typedef TArrayAsVectorIterator<Position> TRectArrayIterator;
> 

Nein,
die Client-Klasse des Templates 'TArrayAsVector' muss vermutlich
einen Vergleichsoperator bereitstellen. Der Copy-Constructor wird,
falls er nicht vom Benutzer definiert wird, vom Compiler generiert
und fuehrt eine komponentenweise Initialisierung durch.Das erscheint
hier durchaus sinnvoll.
Der Vergleichsoperator sollte allerdings einen ganzzahligen Wert
zurueckliefern, z.B:

	int operator == (const Position& mc) const {
		return xz==mc.xz && yz==mc.yz;
	}

	Enno
Re: Brauch Hilfe bei Container-Arrays ???
#1998
Author: Dietmar Kuehl
Date: Thu, 04 Apr 1996 13:29
31 lines
1558 bytes
Hi,
Christian Groeling (Ch.Groeling@kassel.netsurf.de) wrote:
: ich wollte eigentlich nur erklärt haben warum der unten aufgeführte
: Teil eines C++ Listings die Zeile " int operator==(const Position& mc)
: const{} " braucht (und warum). Ich weiss es hat irgendetwas mit einem
: Copy Konstruktor zu tun. 

: class Position
: {
: 	 public  :
: 			int xz;
: 			int yz;
: 			void eingabe(int x,int y) {xz=x;yz=y;}
: 			Position(){
: 			xz =0;
: 			yz =0;
: 			};
: 			int operator==(const Position& mc) const{};
: };

: typedef TArrayAsVector<Position> TRectArray;
: typedef TArrayAsVectorIterator<Position> TRectArrayIterator;

Diese Frage laesst sich nur mit Kenntnis von 'TArrayAsVector'
beantworten. Da diese Klasse Teil einer spezifischen Klassenbibliotek
ist, ist sie "environment specific" und hat in de.comp.lang.c++ nicht
zu suchen. Du solltest sie in einem entsprechenden Forum fragen.
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl/
I am a realistic optimist - that's why I appear to be slightly pessimistic
Re: Brauch Hilfe bei Container-Arrays ???
#2003
Author: Ralf W. Stephan
Date: Thu, 04 Apr 1996 13:34
23 lines
1361 bytes
Christian Groeling writes:
> ich wollte eigentlich nur erklärt haben warum der unten aufgeführte
> Teil eines C++ Listings die Zeile " int operator==(const Position& mc)
> const{} " braucht (und warum). Ich weiss es hat irgendetwas mit einem
> Copy Konstruktor zu tun. 

Wenn ja, dann sollte es wohl so aussehen:
Position (const Position& mc) { xz = mc.xz; yz = mc.yz; }

Oder meinst Du den Zuweisungsoperator?  Dann wäre das:
Position& operator=(const Position& mc) 
                              { xz = mc.xz; yz = mc.yz; return *this; }

Oder meinst Du wohl doch den Vergleichsoperator, dann eben:
bool operator==(const Position& mc) const { return xz==mc.xz && yz==mc.yz; }


ralf
--
"In some ways the online environment in 1996 feels like Hong Kong in the 
last days of British rule: a very free community wondering what's going to 
happen as the forces of law and order start moving in." --Charles Platt   
PGP: 1024/0xA713ECE9 2047/0xC8E605F5    keys on servers
Re: Brauch Hilfe bei Container-Arrays ???
#2029
Author: Christian Groeling
Date: Sat, 06 Apr 1996 00:31
8 lines
572 bytes
Moin,

ne ich meinte den Copy-Konstruktor, und damit hat sich meine Frage
auch schon erledigt.

Danke LEUTE !!

Gruss Chris !
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