Reputation: 775
could someone please help to solve this error :
test.cpp(14) : error C2079: 'x1' uses undefined struct 'x'
test.cpp(16) : error C2228: left of '.x_x1' must have class/struct/union type
here is a part of the code:
struct x x1;
...
x1.x_x1=y_x1;
On unix, the program is compiling and linking without errors. Thanks for your help ,
Upvotes: 2
Views: 5478
Reputation: 17411
With just a forward declaration, you can only define a pointer or a reference to the struct
, you can't access the members (x1.x_x1
) of a struct
.
Include the full definition of the struct if you want to access members.
E.g. following would work:
struct x {
int x_x1;
};
struct x x1;
...
x1.x_x1=y_x1;
// or
#include "struct_x.h"
struct x x1;
...
x1.x_x1=y_x1;
where struct_x.h has:
struct x {
int x_x1;
};
Upvotes: 1