This may not be perfect, but if you trully want to have overloads with int and pointer, you could use some helper class like this:
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
template<typename T = void> class ptr {
T* it;
public:
ptr(T* it = nullptr): it(it) {}
ptr(const ptr<T>&) = default;
ptr& operator = (const ptr<T>&) = default;
operator T* () { return it; }
T& operator * () { return *it; }
T* operator -> () { return it; }
ptr& operator += (int x) { it += x; return *this; }
ptr& operator -= (int x) { it -= x; return *this; }
ptr& operator ++ () { ++it; return *this; }
// etc...
public:
template<typename P>
ptr(P* it): it(it) {}
template<typename P>
ptr(ptr<P> it): it((T*)it) {}
};
template<> class ptr<void> {
void* it;
public:
ptr(void* it = nullptr): it(it) {}
ptr(const ptr<void>&) = default;
ptr& operator = (const ptr<void>&) = default;
operator void* () { return it; }
public:
template<typename P>
ptr(P* it): it(it) {}
template<typename P>
ptr(ptr<P> it): it((void*)it) {}
};
void a(std::size_t x) {
cout << "first: " << x << endl; }
void a(ptr<const int> p) {
cout << "second: " << (p ? *p : -1) << endl; }
void a(ptr<int> p, ptr<> q) {
cout << "third: " << (p ? *p : -1) << ", "
<< (q ? "some" : "null") << endl;
a(p); }
int main(){
a(0); // first: 0
a(NULL); // first: 0 but warning [-Wconversion-null]
a(new int(3), nullptr); // third: 3, null + second: 3
}
It is not finished (maybe remove that explicit, add more operators, special conversion from nullptr_t, etc), just and idea.
EDIT: Few changes in code, template constructors and conversion to ptr<const int>
test.