In C ++, I want to have a class whose constructors are as follows:
class A {
explicit A(A* other) { ... }
explicit A(intptr_t other) { ... }
};
The problem with this is that the user is initializing with
A a(0);
Then, on a 64-bit system, the compiler will complain that it does not know whether to convert 0to A*or to intptr_t, which is fair enough. Since I want this simple notation to work, I added the following constructor:
explicit A(int a) { assert(a==0); ... }
The statement is that it is the only whole for which it makes sense. Now the problem arises with a 32-bit system, in which intptr_tactually ... int! So, the system complains that there are two constructors that take the same type of parameter (which is again true).
, : , intptr_t int int. A a(0) int, ( ).