See
user-defined conversion function[
^]. That's a great site, by the way. My go-to for obscure C++ information.
So if you're trying to convert between
Vec3
and
Vector3
, it would be something like this:
struct Vec3
{
operator Vec3(const Vector3& v); operator Vector3(); };
struct Vector3
{
operator Vector3(const Vec3& v); operator Vec3(); };
v1a Vec3(<args1>);
v2a Vector3(<args2>);
v1b Vec3(v2a);
v2b Vector3(v1a);
And now each vector has both versions.
EDIT: Those were converting constructors. If you want a conversion
operator, it has to go in the class being converted. I've edited the above to show them. You can make any of the converters
explicit
if you have problems with unintended conversions, but I don't think that will happen here. It's more likely when providing conversion to basic types, like
bool
.
From the above,
v1a = v2a;
should invoke the conversion operator
Vector3::operator Vec3
.