我想知道这个指针的地址。尝试了以下方式。
谁能建议我正确的方法?
我正在尝试打印 cout<<&this<<endl;
在类成员函数中。但编译器生成错误 C2102:“&”需要左值。
最佳答案
如果我没记错的话,std::cout << this
应该足够了。
class Foo
{
public:
void foo()
{
std::cout << this << std::endl;
}
};
int main()
{
Foo foo{};
foo.foo();
}
关于c++ - 在 C++ 中访问此指针地址的语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21593006/