Compiler error. Problem with class declaration

I don’t know why I get this error.

/Users/dannyswarzman/Documents/Arduino/Test/Test.ino:24:5: error: request for member 'PP' in 'm', which is of non-class type 'MM()'
24 | m.PP();
| ^~
exit status 1

Compilation error: request for member 'PP' in 'm', which is of non-class type 'MM()'

class MM
{
  public:
    MM(){}
    void PP();
};

void MM::PP()
{
  {Serial.println("MM");}
}
MM m();
#include <arduino.h>
void setup() {
  Serial.begin(115200);
  while(!Serial)
    delay(10);
  Serial.println("Begin");

  if(m)
    Serial.println ("m is");
  else
    Serial.println("m isn't");
  m.PP();
}

void loop() {
}

The error message is for the last line of setup().

Show the verbose error log in code tags, there is often more information

When declaring the global m, omit the paranetheses.

#include <arduino.h> will fail on case sensitive OSes, and in any case is included too late to be able to use Serial in class MM.

Declaring m as a global variable means it's not a pointer. So testing if it's not NULL is not correct.

class MM {
 public:
   MM() {}
   void PP();
};

void MM::PP() {
   { Serial.println("MM"); }
}

MM m;

void setup() {
   Serial.begin(115200);
   while( !Serial )
      delay(10);
   Serial.println("Begin");

   m.PP();
}

void loop() {
}

or, if you're commited to the idea of testing m being non NULL, make it a pointer.

class MM {
 public:
   MM() {}
   void PP();
};

void MM::PP() {
   { Serial.println("MM"); }
}

MM *m = new MM;

void setup() {
   Serial.begin(115200);
   while( !Serial )
      delay(10);
   Serial.println("Begin");

   if( m )
      Serial.println("m is");
   else
      Serial.println("m isn't");
   m->PP();
}

void loop() {
}
1 Like