• Advertisement
Sign in to follow this  

unions and what not

This topic is 4604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Could you explain "non-trivial constructor" to me? And umm, so I should just, stick with three separate vector_t's?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement