I know that this question was asked a lot of times but all the threads I read don't solve my problem.
I minimized my code as much as possible.
sketch.ino
#include <dogboxLib.h>
//dogbox dogbox;
void setup() {
// put your setup code here, to run once:
handleFan();
// dogbox.begin();
}
void loop() {
// put your main code here, to run repeatedly:
}
dogboxLib.h
#ifndef dogbox_h
#define dogbox_h
void handleFan();
class dogbox {
public:
dogbox();
void begin();
};
extern dogbox dogbox;
#endif
dogboxLib.cpp
#include "dogboxLib.h"
dogbox::dogbox() {
}
void dogbox::begin() {
}
dogbox dogbox;
dogboxHandler.cpp
#include "dogboxLib.h"
void handleFan() {
dogbox.begin();
}
What I plan to do: I want an object dogbox
of class dogbox
. This is a global variable since I need to work with it in dogboxLib.cpp
, dogboxHandler.cpp
and sketch.ino
.
What I thought would happen: I declared dogbox dogbox
as extern
in dogboxLib.h
so this variable is available for all files that include dogboxLib.h
(= dogboxLib.cpp, dogboxHandler.cpp, sketch.ino). Afterwards I define dogbox dogbox
in dogboxLib.cpp
. So I expected that I can call dogbox.begin()
in dogboxHandler.cpp
.
What actually happens: With the code above I get the following error:
/Volumes/Daten/alve89/Documents/Programmierung/Arduino/libraries/dogBoxLib/dogboxLib.cpp:9:1: error: 'dogbox' does not name a type
dogbox dogbox;
Could someone please tell me what I'm doing and thinking wrong?
Thanks in advance!