Monday, 19 August 2013

Why can't struct variables be initialized after declaration?

Why can't struct variables be initialized after declaration?

I encountered this recently but could not figure out why the language
would allow b = c; below and fail b = {3, 4}. Is there an issue with
allowing the latter ?
struct T {
int x;
int y;
};
int main()
{
T a = {1, 2};
T b;
b = {3, 4}; // why does this fail ?
T c = {3, 4};
b = c; // this works
return 0;
}

No comments:

Post a Comment