I have a problem i have some constructors that are ambiguous one that cast normally and one that tries to reinterpret cast any object this is a simplified version I tried to somehow prioritize them but it was unsuccessful I would appreciate some help to somehow make the use of the memory cast constructor a last resort.
Here is my simplified code:
template<> struct PriorityTag<0> {};
template<typename T>
struct Comps {
T X;
T Y;
};
template<typename T>
class ConstructTest : Comps<T> {
public:
ConstructTest(T x, T y) {
this->X = x;
this->Y = y;
}
template<typename U>
ConstructTest(const Comps<U>& u, PriorityTag<4>) { //try to use this first
this->X = u.X;
this->Y = u.Y;
}
template<typename U>
ConstructTest(const U& u, PriorityTag<0>) {
*this = SomeMemoryCast<ConstructTest>(u); //use as a last resort
}
template<typename U>
ConstructTest(const U& u) : ConstructTest(u, PriorityTag<4>()) {}
};
int main() {
ConstructTest<int> testVal(5, 5);
ConstructTest<float> copyed = testVal;
}```
