两段程序为何结果不同?
两程序为何结果不同?
#include <iostream>
using namespace std;
class glove
{
public:
glove(int numfingers):_n(numfingers),_hand(_n)
{
cout<<"glove with"<<_hand<<"fingers\n";
}
private:
// int _hand;
int _n;
int _hand;
};
int main()
{
glove name(5);
return 0;
}
运行结果:glove with5fingers
#include <iostream>
using namespace std;
class glove
{
public:
glove(int numfingers):_n(numfingers),_hand(_n)
{
cout<<"glove with"<<_hand<<"fingers\n";
}
private:
int _hand;
int _n;
// int _hand;
};
int main()
{
glove name(5);
return 0;
}
运行结果:glove with-858993460fingers
编译器:Microsoft Visual C++ 6.0