using namespace std;
class Counter
{
int val;
public:
Counter() { val = 0; }
int Next() { return ++val; }
};
int main()
{
Counter counter;
while (int c = counter.Next() <= 5)
{
cout << c << endl;
}
}
When run, the program prints out 1 5 times. Thus, .Next() is returning the expected value as the while loop does terminate.
Why is the value of c remain set to the initial value?
I'm very new to C++ (this is the first C++ program I've written) and am just trying to understand how the return value of .Next() could be as expected and evaluated but not captured in the c variable.