Hi!
I get a problem with the vector as a private class member:
When I did't initialize the vector in constructor(which means the size of the vector would be 0), I used a class function to add two elements to the vector and it worked (because I added a "printf" to output the size of the vector and the elements within that function). However, when I used another class function to visit that vector, no element was in and the size became 0.
Then I tried to add two elements to the vector during the construction, and it turned out that these two elements could be stored in the vector while other elements added through class functions could not.
I guess there may be some problems on the scope of the function. But I feel the class member should not be effected by the scope of the class function.
Does any one know why this happen and how to solve it? Thank you for your help!
void main(){
A a;
a.FunctionB(x,y);
a.FunctionA();
}
Here's an example. I thought the output should be 2 but it turned to be 0....
If I add a printf to print the size in FunctionB, the result would be 2 and 0.
If I use the constructor to add two elements in initialization, the result would be 4 and 2.
There may exist grammer error. But I feel that's not the point. After all the program can execute. So I feel the point may be the management of the class or the vector.