Oct 18, 2014 at 3:05pm UTC
Hi guys.
Everytime i create a class header like
1 2 3 4 5 6 7 8 9 10 11
#IFNDEF BLAH_H
#DEFINE BLAH_H
#include "foo"
#include "bar"
class Blah{
};
#ENDIF
And if i add it like #include "blah.h", i also add foo and bar classes and see the functions they provide. Is there a way to prevent this.
Thanks in advance.
Last edited on Oct 18, 2014 at 3:19pm UTC
Oct 18, 2014 at 3:13pm UTC
Not a good way, no. #include is a glorified copy/paste -- it's like you're copy/pasting the header into the file that includes it.
The best way is to simply not include foo/bar in the header.
Oct 18, 2014 at 3:20pm UTC
If i need to use foo and bar classes' functions inside Blah, how else i can add them? An example maybe.
Sorry if i misunderstood.
Last edited on Oct 18, 2014 at 3:21pm UTC
Oct 18, 2014 at 3:22pm UTC
If you don't need the full class you can forward declare them and avoid the include.
If you do need the full class then you'll have to include them. And I guess just live with the fact that they'll also be included in anything that includes your header. =/
Oct 18, 2014 at 3:31pm UTC
So simply put, there is no way :)
Thanks for all the answers anyway. Helped a lot.