unions and what not

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 on other sites
Im not entirely sure here but:

1) no struct type
2) union has no name

ace

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

Create an account

Register a new account

• Forum Statistics

• Total Topics
628308
• Total Posts
2981979

• 9
• 9
• 13
• 11
• 12