E2069 Illegal use of member pointer (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Compiler Errors And Warnings (C++) Index

Pointers to class members can only be passed as arguments to functions, or used with the following operators:

  • assignment operators
  • comparison operators
  • .*
  • -->*
  • ?: conditional (ternary) operator
  • && logical AND operator
  • || logical OR operator

The compiler has encountered a member pointer being used with a different operator.

In order to call a member function pointer, one must supply an instance of the class for it to call upon.

For example:

class A {
public:
   myex();
};
typedef int (A::*Amfptr)();
myex()
{
   Amfptr mmyex = &A::myex;
   return (*mmyex)();  //error
}

This will compile:

class A {
public:
   myex();
};
typedef int (A::*Amfptr)();
foo()
{
   A a;
   Amfptr mmyex = &A::myex;
   return (a.*mmyex)();
}