void testfunc(int x = 0, void called = this){
called->stuff(x);
}
which obviously doesn't compile but is there a way to get the pointer of the object (class) that called the function and then use that in the code of the custom function?
class MyClass{
public:
void testFunc(MyClass* caller);
// or rather than a pointer, I suggest you pass by const reference
void testFunc(const MyClass& caller);
};
if the calling object needs to be modified then you can't pass a const reference of course, but if possible make it const
well that would work if I knew what the class was going to be for sure. but this function can run on a variety of classes. It really needs to be treated almost like a void type...
that code says it's unable to resolve the address of caller whenever I try to use it. Plus you have to specify the object I am calling the function from which I was trying to avoid doing.
But I'm basically calling a function from a window, that does some stuff to the window hence I need the pointer too it.
The catch is there are different types of these windows I'm calling (some not even "windows" at all), so just declaring the function as a member of the window won't work. I need a way to get the window pointer on the fly. I was hoping there was a way to do this without having to specify it each time. And since it will almost always be done on the window that calls it I was hoping for a way to set the window that called it as the default pointer, instead of NULL or something just as useless.
yes, except the classes I'm using are coming from a library I'm using. So I could recreate them in a custom class but that seems a bit hardcore...
I'm currently trying to wrap them in a custom class, but I'm not sure how well that is going to work, we'll see, might even make things more flexible for all I know. Never came across this situation before.