Reputation: 779
can somebody please explain why the following program causing the compilation problem. I have compiled the source code over VS2013.
#include <iostream>
using namespace std;
// Do not work
union myuni
{
string str;
};
void main()
{
}
Does union require the fixed length size while declaring it? The same scenario works fine with structure.
Upvotes: 1
Views: 93
Reputation: 234795
You cannot have a string
in a union
as the former contains a constructor.
(Although allowed in C++11 this is not supported in VS2013).
Upvotes: 6