S
somenath
When I try to compile the following code I get error.
struct Test {
int x;
struct Test t;
};
int main (void) {
}
g++ -ansi -pedantic test.cpp
test.cpp:3:19: error: field ‘t’ has incomplete type
This I can understand. As before the availability of complete “struct Test” declaration I am trying to create an object of that type. So compileris complaining.
But when I change the struct declaration as follows
struct Test {
int x;
static struct Test t;
};
I do not get any error. I am not able to understand what role static is playing here? How compiler is able to obtain the complete definition of struct in presence of static key word?
struct Test {
int x;
struct Test t;
};
int main (void) {
}
g++ -ansi -pedantic test.cpp
test.cpp:3:19: error: field ‘t’ has incomplete type
This I can understand. As before the availability of complete “struct Test” declaration I am trying to create an object of that type. So compileris complaining.
But when I change the struct declaration as follows
struct Test {
int x;
static struct Test t;
};
I do not get any error. I am not able to understand what role static is playing here? How compiler is able to obtain the complete definition of struct in presence of static key word?