Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not Aggregate type? what is that.... help compile

Status
Not open for further replies.

Iceman2005

Programmer
May 6, 2005
22
US
Hi... i wrote a very simple peice of code in windows..
it compiles and works perfectly... but when i port the code to linux... virtually no code change... it does NOT compile.... it gives me the error....

enum.cpp:14: error: `AA::MyEnum' is not an aggregate type
enum.cpp: In function `int main()':
enum.cpp:23: error: `AA::MyEnum' is not an aggregate type

does anyone know why? and how do i make it comppile on linux? thanks.

CODE.............



#include "stdafx.h"

class AA {
public:

enum MyEnum {
x = 1,
y = 2,
z = 4
};


void foo(const MyEnum ee = MyEnum::x)
{
}
};

int main()
{
AA aa;

aa.foo(AA::MyEnum::x);

return 0;
}











thanks,
iceman
 
Try this instead:
Code:
class AA {
public:

    enum MyEnum {
        x = 1,
        y = 2,
        z = 4
    };


    void foo(const MyEnum ee = x)
    {
    }
};

int main()
{
    AA aa;

    aa.foo(AA::x);

    return 0;
}
I'm not good at explaining that particular oddity, but I would have designed the compiler (and language) to work the way you first wrote it...
Basically, x, y & z aren't members of MyEnum the way they would be in a struct or class. Their names are visible without the MyEnum:: scope, which is why you couldn't use those variable names for anything else in the same scope, because they would conflict with the enum members. Think of the enum like it's doing this:
Code:
class AA {
public:

    int x = 1;
    int y = 2;
    int z = 4;
...
};
 
ahhhh... thank you very much.

this indeed helped me.

=)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top