Peter Olcott wrote:
Yesterday I found that an invocation of a member function that
lacked the required "()" pararenthesis did not generate an error
message. This was an invocation of a member function that is part
of a library so I do not have access to the source code. The
compiler was MSVC++ 6.0.
You mean something like below?
| struct foo
| {
| void bar() {}
| };
|
| int main()
| {
| foo f;
| f.bar; // <--- note this line!
| }
I guess you have something like the highlighted line: well,
this is effectively a valid expression which determines a
pointer-to-member-function and discards it unused. The
compiler on the system I'm currently using issues this
message:
| "tst.cpp", line 9: Warning: The value of <expression>.foo::bar
| is unused.
(plus a warning about the uninitialized 'f' but this is
irrelevant to this discussion).
It is possible to make the warning go away by actually using
the value, e.g. by assigning it to a pointer-to-member-function:
| void (foo::*ptmf)() = f.bar;
I can't think of any scenario that would prevent a compiler error
message from being generated. Can some one please explain
how this could have occurred?
I'd guess that the discussion above gives an indication why
the compiler did not issue an error. It might have issued a
warning, though. It is quite similar to a problem I
encountered recently where are program caused real damage
because it executed code it should not have executed under
the given conditions. It turned out that the code was
protected by something like this:
| if (some_condition)
| std::exit;
It's nice to mention the function 'std::exit()'. It would have
been nicer to actually execute it by tagging on parenthesis.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting