Class XXX does not name a type

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!

Hi, I have not tried the code, but the same name for two different things might be a problem. Can you rename one of them ?

I suppose the compiler does not like this:

int int;
myValue myValue;
extern dogbox dogbox;

No… Try something like

extern dogbox myDogbox;

Remember you don’t create variables out of reserve words.

int int;

You’re class name is now a reserve word, sort of.

-jimlee

Alright, it worked, I learned something new - thank you!

You are very welcome!

-jim lee