相关疑难解决方法(0)

地址

我试图找到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

c++ pointers this

11
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

pointers ×1

this ×1