C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

enum - not aggregate type

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Alex Muffmolch
Guest





PostPosted: Mon Dec 01, 2003 1:58 pm    Post subject: enum - not aggregate type Reply with quote



ich habe folgende beispiel-klasse

class A
{
public:
enum INDEX {EINS=1,ZWEI=2};

a(){
feld[INDEX::EINS] = 0;
feld[INDEX::ZWEI] = 0;
}
...
private:
int feld[3];
};

unter windows wird das ganze einwandfrei kompiliert
unter linux kommt der fehler "A::INDEX is not an aggregate type"

ich vermute, der compiler stört sich daran, dass INDEX ein enum und
kein int-Typ ist.
Wie kann ich aber dennoch OHNE "#define" bzw. fester variablen indexe
definieren?
Ziel ist es das ich zwar im enum die index nummern vertauschen kann,
ohne dass ich die feldindizes in den einzelnen funktionen ändern muss?

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Falk Hueffner
Guest





PostPosted: Mon Dec 01, 2003 3:03 pm    Post subject: Re: enum - not aggregate type Reply with quote



[email]muffmolch (AT) gmx (DOT) de[/email] (Alex Muffmolch) writes:

Quote:
ich habe folgende beispiel-klasse

class A
{
public:
enum INDEX {EINS=1,ZWEI=2};

a(){
feld[INDEX::EINS] = 0;
feld[INDEX::ZWEI] = 0;
}
...
private:
int feld[3];
};

unter windows wird das ganze einwandfrei kompiliert
unter linux kommt der fehler "A::INDEX is not an aggregate type"

ich vermute, der compiler stört sich daran, dass INDEX ein enum und
kein int-Typ ist.
Wie kann ich aber dennoch OHNE "#define" bzw. fester variablen indexe
definieren?

feld[EINS] = 0;

Die ::-Schreibweise gibt's nur fuer Klassen und namespaces.

--
Falk

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Markus Breuer
Guest





PostPosted: Mon Dec 01, 2003 3:08 pm    Post subject: Re: enum - not aggregate type Reply with quote



Alex Muffmolch schrieb:

Quote:
ich habe folgende beispiel-klasse

class A
{
public:
enum INDEX {EINS=1,ZWEI=2};

a(){
feld[INDEX::EINS] = 0;
feld[INDEX::ZWEI] = 0;
}
...
private:
int feld[3];
};

unter windows wird das ganze einwandfrei kompiliert
unter linux kommt der fehler "A::INDEX is not an aggregate type"

INDEX ist der Typ, EINS ein möglicher Wert. INDEX ist kein namespace,
daher darfst du ihn auch nicht als solchen verwenden:

feld[EINS] = 0;

oder

feld[A::EINS] = 0;

Der Windows-Compiler schluckt da anscheinend wohl etwas nicht zulässiges!

Gruß Markus

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Alex Muffmolch
Guest





PostPosted: Tue Dec 02, 2003 8:01 am    Post subject: Re: enum - not aggregate type Reply with quote

Markus Breuer <markus.breuer (AT) gmx (DOT) de> wrote

Quote:
Alex Muffmolch schrieb:

ich habe folgende beispiel-klasse

class A
{
public:
enum INDEX {EINS=1,ZWEI=2};

a(){
feld[INDEX::EINS] = 0;
feld[INDEX::ZWEI] = 0;
}
...
private:
int feld[3];
};

unter windows wird das ganze einwandfrei kompiliert
unter linux kommt der fehler "A::INDEX is not an aggregate type"

INDEX ist der Typ, EINS ein möglicher Wert. INDEX ist kein namespace,
daher darfst du ihn auch nicht als solchen verwenden:

feld[EINS] = 0;

oder

feld[A::EINS] = 0;

Der Windows-Compiler schluckt da anscheinend wohl etwas nicht zulässiges!

Gruß Markus

yupp, das scheint der windows compiler zu machen!
bei enums herrscht auch eine eineindeutigkeit, so dürfen in enums
einer klasse auch keine zwei gleichen "namen" stehen:

z.B. enum A {ONE,TWO};
enum B {TWO}; <--- Fehler...

sollte man daher lieber gleich mit namespaces in einer klasse
arbeiten?
was ist der bessere stil?

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.