Sign in to follow this  
andyZER0

unions and what not

Recommended Posts

andyZER0    128
I'm not sure what's happening here, but I'm unable to use this code:
// this is apart of a class called triangle_t
// it uses vector_t's (another class) as triangle vertices
// and..these members are public
union
	{
		struct
		{
			vector3_t a;
			vector3_t b;
			vector3_t c;
		};
		vector3_t vertex[3];
	};

I'm pretty sure this is valid. But I keep getting the compiler error: c:\documents and settings\andrew\my documents\visual studio\projects\gldemo\gldemo\mesh.h(85) : error C2621: member 'triangle_t::vertex' of union 'triangle_t::<unnamed-tag>' has copy constructor I'm not sure how to fix this. What exactly is the problem? vector3_t needs that copy constructor. Thanks in advance.

Share this post


Link to post
Share on other sites
Sneftel    1788
You cannot make a union in which one or more members have nontrivial constructors, since the compiler has no way of knowing which member's copy-constructor to invoke when copying the entire union.

Share this post


Link to post
Share on other sites
mgarriss    154
from the standard:
Quote:

9.5 - Unions [class.union]

-1-
... snip ....
An object of a class with a non-trivial constructor (class.ctor), a non-trivial copy constructor (class.copy), a non-trivial destructor (class.dtor), or a non-trivial copy assignment operator (over.ass, class.copy) cannot be a member of a union, nor can an array of such objects.
.... snip ....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this