Re: what is wrong with this code?
"terry" <news1@lyonstech.net>
This code does not compile unless the second call (at *************) to
the
template function is commented out. It causes fatal error C1001: An
internal
error has occurred in the compiler in VS2008.
Indeed, here too.
What part of the standard am I violating? Thanks! Is there a work around?
(posted a similar question earlier but perhaps there was too much
verbiage -
it would help to know which errors I am making!)
I simplified the code to the bones, it still makes internal error, that is a
bug in MS compiler -- send them a report so it can be fixed.
- ---
struct B
{
int f ( void ) {return 0;}
};
template <typename T>
void loop( T fn )
{
}
int main(int argc, char* argv[])
{
int (B::*mfn)( void ) = &B::f;
B b;
loop(b.*mfn); // bug-triggering line
// fatal error C1001: An internal error has occurred in the compiler.
// (compiler file 'msc1.cpp', line 1411)
return 0;
}
- ---
Cameau reports:
"ComeauTest.c", line 16: error: a pointer to a bound function may only be
used to
call the function
Wild Guess: You're calling a member function and forgot the ()'s
loop(b.*mfn); // bug-triggering line
^
that implies the kind of usage is not allowed. (changing it to a call
loop((b.*mfn)());
makes it compile.
In your original example you need a pointer-to-function passed to loop. The
result of .* and ->* operators do not decay to such a pointer (and it would
not be compatible with regular function pointers).
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]