Using Structs -- Odd Issue
Been awhile since I've used structs in C++.
Any idea why this isn't working? My compiler is complaining about DataStruct not being a recognized type but Intellisense in VC++ is still able to see the data members inside the struct so the syntax is ok...
Frustating. xD
struct DataStruct
{
int first;
};
int main开发者_StackOverflow中文版(int argc, char **argv)
{
DataStruct test;
//test.first = 1;
}
Are you sure you are compiling the file as C++? If you compile it as C (i.e. if the file has a .c rather than a .cpp extension), you will have problems.
You are compiling as C code. C requires you to refer to it using the "Struct" keyword or typedef it. C++ does not.
You need to use struct DataStruct
to refer to the struct.
Alternatively, you can typedef it as DataStruct
if don't want to use the "struct" everywhere.
精彩评论