I have a simple wrapper class for Integer types, defined like so (just an example):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
class Integer {
public:
Integer() {
}
Integer(const int& value) {
this->value = value;
}
int toInt() const {
return value;
}
operator int() const {
return toInt();
}
private:
int value = 0;
};
|
What I'd like to do, is pass the class above to a function which has a signature like this: doSomething(int* value)
This function is outside of my control and cannot be edited (it is in an external library).
If I were to use a normal int, I could simply do:
1 2
|
int value = 5;
doSomething(&value);
|
However, when using the wrapper class I can't since it would use a pointer to the class instead of the actual underlying value. I know of the address operator operator&, which I could use to return a pointer to the value, but it would prevent me from getting a pointer to the class itself if I needed to.
So ideally there would be a way that would allow me to use &myclass to get a pointer to the class or the underlying value, depending on what is needed.
Is there such a way?
I've tried asking this question at Stack Overflow, but since they're so hell bound on knowing why I want to do this and very persistent on not answering the question but trying to circumvent it and give their own opinions on why this or that is bad, I'm going to try it here once again. Sorry for the rant, just had to get that out :)