"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:eW******** ******@TK2MSFTN GP10.phx.gbl...
BG wrote: Here's my program.
{
array<Byte> ^buffer = // something
int length = Array::FindInde x(buffer, gcnew
Predicate<Byte> (&MyClass::isCh ar13) );
try Array.FindIndex (buffer,
gcnew(Predicate <Byte>(this,&My Class::isChar13 );
(assuming this code appears inside another member function MyClass, that
is).
-cd
Hi Carl,
Thanks for your reply.
I tried what you suggested but it didn't compile. Gave the error:
warning C4832: token '.' is illegal after UDT 'System::Array'
g:\windows\micr osoft.net\frame work\v2.0.50727 \mscorlib.dll : see
declaration of 'System::Array'
error C2275: 'System::Array' : illegal use of this type as an expression
g:\windows\micr osoft.net\frame work\v2.0.50727 \mscorlib.dll : see
declaration of 'System::Array'
error C3352: 'bool MyClass::isChar 13(unsigned char)' : the specified
function does not match the delegate type 'bool (unsigned char)'
The last error suggested that the compiler does not expect the function to
be a member of a class. I made appropriate changes and it compiled fine.
But I didn't like this solution. What if I wanted to make a class member
function my predicate? So again, taking a cue from the last error, I read
the documentation on delegates. (Being new to C++/CLI. I still don't many of
these basic things that you probably take for granted).
I then made the function a member of the class again, but changed the call
to it like so
int length = Array::FindInde x(buffer, gcnew Predicate<Byte> (this,
&MyClass::isCha r13) );
That is, introduced 'this' as the first arg to Predicate ctor.
That worked!
I am still looking at the documentation to fully understand the reasons. But
if you do, please do post.