当我cout
将lettercase
变量转到控制台时,我得到-858993460
. 其他一切似乎都工作正常。我在这里想念什么?
所以这是我的代码示例:
这里主要:
int main()
{
int lettercase = 0;
Switch switcher(lettercase);
lettercase = switcher.getLettercase();
cout << "Lettercase: " << lettercase << endl;
return 0;
}
我还有一个单独的类,称为Switch
. 这是其头文件的示例:
class Switch {
public:
// DEFAULT CONSTRUCTOR
Switch();
// OVERLOAD CONSTRUCTOR
Switch(int);
// DESTRUCTOR
~Switch();
// Lettercase accessor
int getLettercase();
private:
int lettercase;
};
这是我的定义示例:
// DEFAULT
Switch::Switch() {
int lettercase = 0;
}
// OVERLOAD
Switch::Switch(int lettercase) {
// CHANGE LETTER CASE
if (lettercase == 1) {
lettercase = 0;
} else {
lettercase = 1;
}
}
// DESTRUCTOR
Switch::~Switch() {
}
// ACCESSOR
int Switch::getLettercase() {
return lettercase;
}