"static array?" <
XXXX@XXXXX.COM >writes:
Quote
** Q: Why with this construct do I get a compiler error:
ActionMakeDistribFiles->OnUpdate = EnableActions ?
ActionMakeDistribFilesUpdate : NULL;
[C++ Error] MainForm.cpp(3945): E2235 Member function must be called or its
address taken
First, be aware that __closure objects (the thing a TAction holds) is
not part of C++ at all, and is purely a Borland/CodeGear extension to
the language for Delphi compatibility. As such, no rules in the
language dictate what should happen when you use them.
As is common with other Delphi-C++ object model mergers, it works "for
the most part" but there tends to be some rough edges, and I think
you've stumbled across one.
The ternary operator forms an expression, which always has a value of
a single "type", and that type must be determined at compile time by
picking between the two expressions in the result of the operator. In
this case, you're passing a member function name, which by itself is
not a vaild expression.
However, when you assign a member function name to a __closure, BCB
does its magic and converts it to a __closure. I think that their
language extension is not fully integrated into the language.
For true C++ member function pointers (which are distinctly different
from __closures), the syntax REQUIRES that you use the address-of
operator and a class qualification. For example,
class X
{
void foo();
};
A member function pointer to X::foo would be &X::foo (and never just
foo, never X::foo, and never &foo.
Quote
BUT when I simply use If/else:
if (EnableActions)
ActionMakeDistribFiles->OnUpdate = ActionMakeDistribFilesUpdate;
else
ActionMakeDistribFiles->OnUpdate = NULL;
it compiles and works fine.
This is directly assigning to the closure, without the machinery of
the ternary operator getting in the way and confusing the compiler.
In that regard, I think __closures are not first-class objects in BCB,
but are only partially integrated for the common cases.
--
Chris (TeamB);