.cpp / .h file with classes

Hello everyone!

Maybe my questions are too trivial. I want to have all my classes for a project in an external file.

  1. Why do you always find the extern lol LOL; // myFun.h in examples on the internet? It seems to work without it.

  2. Why does the class “lol” in the .ino-File not appear yellow?

  3. lol LOL=lol(); // Auslagern.ino creates an instance of the class lol right? Do I need to create instances of every used class in the .ino-File or can this be done in the specific .cpp file?

Thank you for answers, best

Sam–

// Auslagern.ino
//
#include <MyFun.h>

lol LOL=lol();

void setup(){
}

void loop(){
  LOL.test();
}
// MyFun.h
//
#ifndef MyFun_h
#define MyFun_h

class lol {
public:
	void test(void);
};

extern lol LOL;

#endif
//MyFun.cpp
//
#include <MyFun.h>

void lol::test(void){

}
  1. Why do you always find the

You don't. There a plenty of classes, like SoftwareSerial, that do not create an instance of the class.

  1. Why does the class "lol" in the .ino-File not appear yellow?

Because you did not (properly) create a keywords.txt file.

creates an instance of the class lol right?

Incorrectly, but yes.

lol lotsOfLeds;

properly creates an instance of the class.

Do I need to create instances of every used class in the .ino-File or can this be done in the specific .cpp file?

Instances of the class should be created where needed - in the sketch, usually, not in the source file of the class.