Something like this?
#include <iostream>
class A
{
int32_t value1_;
int64_t value2_;
private:
template<int sz> struct traits { using type = void; };
template<> struct traits<4> { using type = int32_t; };
template<> struct traits<8> { using type = int64_t; };
template<int sz> typename traits<sz>::type Get() const;
template<> traits<4>::type Get<4>() const { return value1_; }
template<> traits<8>::type Get<8>() const { return value2_; }
public:
A() : value1_(10), value2_(20) {}
template<typename T>
explicit operator T() const
{
return Get<sizeof(T)>();
}
};