I wrote a small library, that essentially is a sub-class of another working library.
My library header has the following:
#include <Arduino.h>
#include <MainClass.h>
My library ccp file has:
#include "MyLib.h"
My sketch has:
#include "MyLib.h"
It does not verify, it says:
MyLib.h:12: error: expected class-name before '{' token
and some other erros related to variables that don't name a type
If I add this line
#include <MainClass.h>
to my sketch, it verifies/uploads/works just fine. Why?
I must specify that the sketch doesn't contain any direct reference to the MainClass, it only uses an istance of MyLib class.
Thank you
There are a number of other threads that deal with why. The IDE copies files to another directory for compiling. What it copies is the sketch and any files related to #include statements in the sketch, but NOT in files included in the sketch.
but removing that line I don't mean to hide the use of the library. The sketch uses the subclass, and that one is seen as library, so it's not a matter of the writer of the sketch to include its superclass if he already included the subclass. Usually it should work like this, or not?
I haven't tried it, but it might be possible to trick the IDE into thinking that the #included file is part of the project, while excluding it from compilation of the .ino file, by enclosing the #include line in #ifdef UNDEF / #endif lines.
Dimitree:
but removing that line I don't mean to hide the use of the library. The sketch uses the subclass, and that one is seen as library, so it's not a matter of the writer of the sketch to include its superclass if he already included the subclass. Usually it should work like this, or not?
Is this subclass in a different directory to the main class?