I browsed many similar questions but cannot find an answer fitting to my problem. I try to create a abstract class and extend that in a different .cpp
file. If I try to compile i am getting this error.
In file included from src/main.cpp:6:0:
src/MQBIOTExecutor.cpp:4:7: error: redefinition of 'class MQBIOTExecutor'
class MQBIOTExecutor
^
In file included from src/MQBIOT.cpp:3:0,
from src/main.cpp:5:
src/MQBIOTExecutor.cpp:4:7: error: previous definition of 'class MQBIOTExecutor'
class MQBIOTExecutor
^
In file included from src/MyExecutor.cpp:3:0,
from src/main.cpp:7:
src/MQBIOTExecutor.cpp:4:7: error: redefinition of 'class MQBIOTExecutor'
class MQBIOTExecutor
^
In file included from src/MQBIOT.cpp:3:0,
from src/main.cpp:5:
src/MQBIOTExecutor.cpp:4:7: error: previous definition of 'class MQBIOTExecutor'
class MQBIOTExecutor
^
I have already tried many things like putting the abstract class into a header file or making all function pure virtual and not pure virtual etc.
My MQBIOTExecutor.cpp
#include <Arduino.h>
#include <ArduinoJson.h>
class MQBIOTExecutor
{
public:
virtual void getState() = 0;
virtual void getCommands() = 0;
virtual void executeCommand(JsonDocument jdoc) = 0;
virtual void getConfig() = 0;
virtual void setConfig(JsonDocument jdoc) = 0;
virtual void getSensor() = 0;
virtual void extend(String topic, String payload, JsonDocument payloadJsonDoc) = 0;
};
My MyExecutor.cpp
#include <Arduino.h>
#include <ArduinoJson.h>
#include <MQBIOTExecutor.cpp>
class MyExecutor : public MQBIOTExecutor
{
public:
virtual void getState()
{
}
virtual void getCommands()
{
}
virtual void executeCommand(JsonDocument jdoc)
{
}
virtual void getConfig()
{
}
virtual void setConfig(JsonDocument jdoc)
{
}
virtual void getSensor()
{
}
virtual void extend(String topic, String payload, JsonDocument payloadJsonDoc)
{
}
};
The rest is irrelevant. If I remove the inheritance the whole thing compiles.