disccip disccip - 5 months ago 95
C++ Question

"expression must be an l-value or function designator" error when taking the address of this

I'm trying to do this in C++:

class Abc
int callFunction1()

void function1(Abc** c1) {//do something}

int Abc::callFunction1()
return 0;

And I get "expression must be an l-value or function designator" error in visual studio 2015. So I don't understand where I go wrong. To my knowledge,
should have the type

The function definition isn't mine to change. So I can't just change the parameter type.

Answer Source

The expression this is an rvalue, the same way that the expressions 137 or 'a' are, and so you can't take its address.

If you want to get a pointer to a pointer to this, you'll need to create a new variable of the right type:

auto* ptr = this;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download