I have to create a factory method which can create objects from different libs. My directory tree looks like this:
libA/src/…
libB/src/…
libC/src/…
src/…
libA, libB, etc are compiled separated.
Let the factory class be in libA/src/Factory.h. It should create an object from libB/src/someclass.h.
If i include ../../libB/src/someclass.h in Factory.h, then libA cant compile, because it can’t find includes from someclass.h (The comiler looks for them in libA/src, but those are in libB/src) If i don’t include, it doesn’t know Someclass, so i can’t create an instance of it.
Is there any solution for this?
You’re looking for forward declaration: in headers where the class only needs to know the type, declare it with
class AFactory;instead of including the whole Factory.h.See this tip for more info.
EDIT
Having re-read your question, I find a contradiction between the fact that you want libraries to be compiled separately, and that factory of libA must know class libB. You can’t compile separately then, so I would simply provide all necessary directories paths to include path.