class foo
{
private:
int x;
public:
void GetX(int* value)
{
value = &x;
}
void setX(int value)
{
x = value;
}
};
int main()
{
foo fooObject;
fooObject.setX(5);
int value;
fooObject.GetX(&value);
std::cout << value; // Prints out garbage value though variable named value is still in scope
}
根据我的意见,值作为参考传递,它指向变量x,并且在打印出值时仍在范围内。