"this" as a default argument value [duplicate]

  c++, function, oop

I want to pass this as a default value to a function.

Like:

template<typename T> 
void fn(int a, T* = this)
{
    ....
}

But I want this to be from the class that’s calling it, not the class it’s defined in.

Alternatively, if there’s a way to automatically pass this in that can also work.

Source: Windows Questions C++

LEAVE A COMMENT