我试图找到this指针的地址,但这段代码显示一个奇怪的错误:
#include <iostream>
using namespace std;
class Base
{
public:
void test()
{
void *address_of_this =&this;
cout<<address_of_this<<endl;
}
};
int main()
{ Base k;
k.test();
return 0;
} //error non-lvalue in unary'&'
Run Code Online (Sandbox Code Playgroud)
你能解释一下这个错误吗?
还指出什么是非法的地址this?