In C ++, any expression followed by a semicolon is a legal statement. (Why? Because C will allow you to do this, I think). This means that all of the following legal statements:
5; 3 + 5; 1 % 2 == 0;
The effect of an expression of this form is that the expression is evaluated and then discarded. A good optimizing compiler will simply eliminate all the logic here, since none of them have side effects.
In your case, write
accept;
is a legal statement because accept is an expression evaluating a reference to the accept function. This means accept; as an operator means "evaluate the accept address and then discard it." The reason no function is called here is because the name of the function itself does not call the function; you need parentheses (function call statement) for the actual call. This is useful, for example, if you want to pass a function to another function. For example, you can pass the comparison function to std::sort , for example:
std::sort(range.begin(), range.end(), nameOfMyComparisonFunction)
It would be a real problem if this would cause a nameOfMyComparisonFunction call, since the arguments cannot be known until the sorting procedure begins.
So why is this a warning and not an error? Well, this is perfectly legitimate C ++ code, so the compiler cannot properly call it an error. However, the compiler has the right to flag this as a warning, as it almost certainly means that you made a mistake. However, most compilers have some setting that warns of warnings as errors, and if you raise the warning level high enough, the compiler will probably say: "This is so suspicious that I'm going to assume that you messed up something."
As for your last - why
bool a = accept;
end up a to true? In C ++, any non-bubble pointer is implicitly converted to true, and any null pointer is implicitly converted to false. In C ++, functions are implicitly converted to pointers to themselves, so in this case, accept evaluates the address of the accept function, which is not zero, therefore sets a to true . When you write
cout << a << endl;
the value prints as 1 since bool values print as 1 and 0, not true and false by default. However, you can write
cout << boolalpha << a << endl;
and instead you will see true .
Hope this helps!