小编Rob*_*tin的帖子

C++非类范围替换this.x = x;

在C++中,我可以在类中执行此操作:

class MyClass {
    public:
        int number;
        void SetNumber(int number);
};

void MyClass::SetNumber(int number)
{
    this->number = number;
}
Run Code Online (Sandbox Code Playgroud)

但是这个怎么样:

int number;

void SetNumber(int number)
{
    //What do I do here?
}
Run Code Online (Sandbox Code Playgroud)

这个问题是因为范围没有"this",类只有"this".有任何想法吗?

c++ methods class this

2
推荐指数
1
解决办法
98
查看次数

标签 统计

c++ ×1

class ×1

methods ×1

this ×1