I am trying to write a class that implements 64-bit ints for a compiler that does not support long long , which will be used in existing code. Basically, I should have somewhere a typedef that selects whether I want to use long long or my class, and everything else should compile and work.
So, I obviously need conversion constructors from int , long , etc. and corresponding conversion operators (castings) to these types. This seems to be causing errors with arithmetic operators. Using native types, the compiler “knows” that when calling operator*(int, char) it must advance char to int and call operator*(int, int) (instead of, for example, casting int to char )). In my case, this is confused between the various built-in operators and the ones I created.
It seems to me that if I can somehow declare the conversion operators explicit, this will solve the problem, but as far as I can tell, the explicit keyword is only for constructors (and I cannot make constructors for built-in types).
So, is there a way to mark the cast as explicit? Or am I barking the wrong tree here and there, another way to solve this? Or maybe I'm just doing something else wrong ...
EDIT:
A little clarification as to what I want to do: I have a project that uses 64-bit (long long) operations in many places, and I'm trying to port it to the platform, in support of 64-bit variables / operations. Despite the fact that I have a source for the project, I would prefer not to go through thousands of places where the built-in operators and casts in the style of C and change them.
As for the code itself, the project has the following definitions and types of code:
typedef long long i64;
Regarding the implementation of the class, I have the following:
class Long64 { public: Long64(); Long64(const Long64&); Long64(int); Long64(long); Long64(unsigned int); Long64(unsigned long); operator int() const; operator long() const; operator unsigned int() const; operator unsigned long() const; friend Long64 operator*(int l, const Long64& r); friend Long64 operator*(const Long64& l, int r); friend Long64 operator*(long l, const Long64& r); friend Long64 operator*(const Long64& l, long r); }