編集:以下からのアドバイスのおかげで問題を修正しました。Evaluation() の戻り値の型を int から void に変更しました。
クラスの使い方を学んでいますが、問題が発生しています。次のような出力が得られます。
0
They are not equal.
4469696
その最後の数字はどこから来たのですか?行の後のどこかにあるはずです
std::cout << Thing.evaluation(Thing.getValue()) << std::endl;
しかし、その値を出力している可能性のあるものは何もありません。メモリリークですか?
#include <iostream>
#include <conio.h>
class classTest
{
public:
int equivalency(int x, int y)
{
if (x == y)
{
value = 1;
} else
{
value = 0;
}
}
int evaluation(int z)
{
if (z == 0)
{
std::cout << "They are not equal." << std::endl;
} else
{
std::cout << "They are equal." << std::endl;
}
}
int getValue()
{
return value;
}
private:
int value;
};
int main()
{
int a = 0, b = 0;
classTest Thing;
std::cout << "Enter two numbers for comparison." << std::endl;
std::cin >> a >> b;
Thing.equivalency(a, b);
std::cout << Thing.getValue() << std::endl;
std::cout << Thing.evaluation(Thing.getValue()) << std::endl;
getch();
return 0;
}