Compiler Error 504 D

nonstandard form for taking the address of a member function

  • If the address of a member function is needed, you should write a pointer to it in the following form. &myClass::myMemberFunction Be careful that this is really what you intend to do.
  • Keep in mind that some built in classes like Ticker, InterruptIn, and TimeOut use a different number of inputs if calling a member function instead of a static function.
  • This error could also happen if a variable and a function in the same scope have the same name. The compiler gets them confused. For example, public access functions in a class should have a slightly different name than the private variable they access.

class Example
{
  public:
    //the compiler will get confused about whether you want to return the integer foo,
    //or if you want to return a pointer to the function foo. It assumes you want to use a function pointer.
    //an error is raised because the correct way to write a function pointer is &foo.
    int foo() { return foo;}
  private:
    int foo;
}

To fix the above example, assuming you want foo() to return the integer foo, give the integer foo a slightly different name:

class Example
{
  public:
    int foo() {return m_foo;}
  private:
    int m_foo; //m_ stands for "member variable"

All wikipages