johnthomaswarner
asked on
C language in Visual studio Struct within a struct: error CXX0025: Error:operator needs class/struct/union
Hopefully someone can tell me what I'm doing wrong.
I have a struct that contains a struct. When I try to access properties of the struct contained
within the first struct, I receive an error:
CXX0025: Error:operator needs class/struct/union
From what I can tell this is proper syntax in C; however, there must be something specific
to the Microsoft C++ compiler that I'm not getting.
I created a win32 project in visual studio 2008.
Thanks.
void testStructConcept()
{
struct first_structure_type
{
int integer_member;
float float_member;
};
struct second_structure_type
{
double double_member;
struct first_structure_type struct_member;
};
struct second_structure_type demo;
demo.double_member = 12345.6789;
demo.struct_member.integer _member = 5;
demo.struct_member.float_m ember = 1023.17;
}
I have a struct that contains a struct. When I try to access properties of the struct contained
within the first struct, I receive an error:
CXX0025: Error:operator needs class/struct/union
From what I can tell this is proper syntax in C; however, there must be something specific
to the Microsoft C++ compiler that I'm not getting.
I created a win32 project in visual studio 2008.
Thanks.
void testStructConcept()
{
struct first_structure_type
{
int integer_member;
float float_member;
};
struct second_structure_type
{
double double_member;
struct first_structure_type struct_member;
};
struct second_structure_type demo;
demo.double_member = 12345.6789;
demo.struct_member.integer
demo.struct_member.float_m
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked! Is this specific to the Visual C++ compiler or is this a C thing?
ASKER
Very fast response!
Well, the specifics for using local classes/structs are part of the C++ standard; however, VS2008 is a little bit loose with this. In this case, your original code should have compiled (and does in gcc) but my experience of Visual Studio is that it doesn't play well with local classes/structs and the reasons for using them are rarely enough to justify the confusion they cause to others or the compiler.
NB. Although you can define structs in a function the semantics are somewhat different to defining them outside a function (the normal place for you to put them).
Open in new window