Arduino: "error: unknown type name 'class'" when compiling

It took me a while to figure out while I had this error when compiling my Arduino sketch.
My project was spread on several files I created. My class was actually defined in a header file (mb8877.h),

class mb8877 {
 ...
};
 
but some functions belonging to the class were defined in another file (mb8877.c) such as:

void mb8877::decode_command() {
 ...
}

That was my mistake!

The rule is: if your define functions belonging to a class outside the header file, the file declaring them should bear a .cpp extension.
Simply renaming mb8877.c to mb8877.cpp cleared the error.

Comments

Popular Posts