•      Sign In
• Create Account

#ActualmadRenEGadE

Posted 09 May 2012 - 12:26 PM

Hello all,

recently I decided to discard my hand-written math library code and use the GLM library.

Because I want to make it "feel" like my own code need some thin wrapper around it. Because performance matters I don't want to
write the wrapper using inheritance like this:

class Vector3 : public glm::dvec3
{
};


Now I have the idea to use a union and write code like this:

union Vector3
{
public:
Vector3(double x, double y, double z)
: v(x, y, z)
{
}

double x, y, z;

private:
glm::dvec3 v;
};


Is this valid code (using C++11)?

#1madRenEGadE

Posted 09 May 2012 - 12:25 PM

Hello all,

recently I decided to discard my hand-written math library code and use the GLM library.

Because I want to make it "feel" like my own code need some thin wrapper around it. Because performance matters I don't want to
write the wrapper using inheritance like this:

class Vector3 : public glm::dvec3
{
};


Now I have the idea to use a union and write code like this:

union Vector3
{
public:
Vector3(double x, double y, double z)
: v(x, y, z)
{
}

double x, y, z;

private:
glm::dvec3 v;
};


Is this valid code (using C++11)?

PARTNERS