Hi all, please search my code first:
#include <iostream>
#include <string>
class character
{
public:
void showX();
private:
int x;
};
void character::showX()
{
x=0;
cout << x << endl;
x++;
cout << x << endl;
}
void main()
{
character black;
black.showX();
black.showX();
}
finally, output shows:
0 1
0 1
it seems the x is initialized after being invoked a second time. it looks a bit like const not variable here, and it confused me much, what cause it be ???![]()



LinkBack URL
About LinkBacks



