Reputation: 279
I have a totally noob-question...
I use Arduino IDE 2.2.1 and have defined this class, but keep getting the error unknown type name 'class'. I used this tutorial as a base: https://arduinogetstarted.com/faq/how-to-create-class-and-object-on-arduino-ide
The compiler presents me of this list:
\Wificonfiguration.c:2:
\Wificonfiguration.h:7:1: error: unknown type name 'class'
\Wificonfiguration.h:7:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
\Wificonfiguration.c:3:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
\Wificonfiguration.c:8:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
I focus on the first line, as it apparently looks for a non-existing .c-file and not a .cpp with OOP-support. Could this be an issue, related to the IDE itself - a configuration, perhaps? Or is it something in my code?
Wificonfigurationmenu.h
// WiFi
#ifndef Wificonfigurationmenu_h
#define Wificonfigurationmenu_h
#include <Arduino.h>
class Wificonfigurationmenu {
private:
int wifiIndex;
public:
Wificonfigurationmenu();
};
#endif
Wificonfigurationmenu.cpp
#include "Wificonfigurationmenu.h"
Wificonfigurationmenu::Wificonfigurationmenu() {
Serial.println("Wifi constructor");
}
GPIO-example.ino
#include "Wificonfigurationmenu.h"
void setup() {
Serial.begin(115200);
...
Upvotes: 1
Views: 1674
Reputation: 607
The Arduino IDE does a bunch of pre-processing on your actual files and copies them into a temp directory. The various compilation and linker steps are then performed from here. If there's multiple versions of the same file with .c
and .cpp
extensions then it seems to pick the .c
in preference, which won't compile as C++.
On Windows the temp directory is at C:\Users\<user>\AppData\Local\Temp\arduino\sketches
by default.
I think this situation probably arises because you originally called your new file as thing.c
before realising your mistake and renaming it to thing.cpp
, but the IDE doesn't delete the old temp copy it created, so now both exist.
Deleting the sketch dir from that temp directory forces the IDE to rebuild everything, and this problem goes away
Upvotes: 3
Reputation: 279
The code worked. For reasons unknown, the Arduino IDE was causing trouble. Removing it, using the Windows uninstaller and then reinstalling made no difference. I had to erase every trace of Arduino IDE from my hard drive before reinstalling - libraries, temporary files, everything.
After a fresh installation, it compiled just fine.
Upvotes: -1