/* simple class that has a vector of ints within it */
class A
{
public:
vector<int> int_list;
};
/* some function that just returns an int, defined elsewhere */
int foo();
/* I want to fill the object's int_list up */
A a_obj;
int main() {
for (int i = 0; i < 10; i++) {
int num = foo();
a_obj.int_list.push_back(num);
}
}
num
的範圍是否僅限於for循環?一旦for循環退出,它會被銷燬嗎?如果我嘗試訪問a_obj
的號碼int_list
中的號碼,我將無法將其中的號碼銷燬嗎?關於我的變量範圍需要一些解釋
非常感謝你,這正是我所需要的:) – martega
@martega:我知道:) –