Главная страница | назад





Article #19433: Cannot convert 'void (* (_closure )())()' to 'void (MyClass::*)()'

 Question and Answer Database

FAQ4433C.txt   :Cannot convert 'void (* (_closure )())()' to 'void (MyClass::*)()'
Category   :Compiler
Platform   :All-32Bit
Product    :All-CBuilder,   

Question:
Why am I getting the error:
Cannot convert 'void (* (_closure )())()' to 'void (MyClass::*)()'
I'm not even using the VCL or closures in my program!

Answer:
This is likely a programming error on your part.  If you are trying
to use a pointer to a non-static member function, check the syntax
to ensure you are following the C++ rules for taking the address of
a member function.
Before C++Builder, your code would have got the more descriptive
error message 'function must be called or its address taken'.  But in
C++Builder it is perfectly valid to take the address of a non-static
member function using the same syntax as for taking the address of a
non-member function (or a static member function): That's the syntax
for accessing a closure.  A closure is a non-static member function
that does not need to be bound to an object.


// To see an example of how not to take the address of a non-static member
// function, compile with:
//   bcc32
// To see the correct way, compile with:
//   bcc32 -DCORRECT
//
struct Sonne
{
  typedef void (Sonne::*SonnePtr)();
  void gdj(){}
  void bmj( SonnePtr p ){}
  Sonne()
  {
#ifdef CORRECT
    bmj( &Sonne::gdj );
#else
    bmj( &gdj );  // valid for closures, not non-static member functions!
      // -or-
//  bmj( gdj );   // valid for closures, not non-static member functions!
#endif
  }
};


3/11/99 10:55:56 AM
 

Last Modified: 01-SEP-99