I tried to wrap something similar to Qt\'s shared data pointers for my purposes, and upon testing I found out that when the const function should be called, its non-const ve
If you have two overloads that differ only in their const
-ness, then the compiler resolves the call based on whether *this
is const
or not. In your example code, test
is not const
, so the non-const
overload is called.
If you did this:
testType test;
const testType &test2 = test;
test2->x();
you should see that the other overload gets called, because test2
is const
.