I'm creating domain objects in my project. Each object has its own .h and .cpp file. Some objects aggregate other objects. As a result, the header for the aggregator would #include the header for the aggregatee (this thread on StackOverflow shows that it's not a bad idea, generally).
I want to keep all of the files in the same directory, rather than creating libraries (at least for now).
I have the #ifndef guards (include guards). So far, I was able to compile a program with 1 level of #includes. When I have added the 2nd level of #includes, I'm getting compilation errors. Does Arduino have any caveats in this area?
Any suggestion, insight or reference is really appreciated!
Some objects aggregate other objects. As a result, the header for the aggregator would #include the header for the aggregatee (this thread on StackOverflow shows that it's not a bad idea, generally).
What do you mean by "aggregate" ?
This isn't a standard word, and could have several possible meanings.
Do you want subclasses or derived classes ?
Do you want something like an array of some object ?
Do you want some kind of container which other object get put into ?
You certainly can have header files which include other header files. Often, you want the header file not to be included more than once, which is why header files often look like this:
#ifndef myClass_H
#define myClass_H
// all the declaration stuff
#endif
Ultimately, I have found explanation for my #include doubts. I've made my #includes work. I had the #ifndef guard in the .h files all along. It turned out that the problem was in something else, and not in how headers were #included. I'm not very familiar with the Arduino IDE, and I don't have a good intuition for the compiler and linker error messages.
What do you mean by "aggregate" ? This isn't a standard word, and could have several possible meanings.
Yes, I want to have a ClassB, which inherits from ClassA. The latter is declared in its own header ClassA.h . (But composition is more important for me than inheritance.)
Do you want something like an array of some object ?
Yes.
Do you want some kind of container which other object get put into ?