In C++ and Objective-C, I’ve gotten into the habit of forward-declaring any necessary classes that do not need to be defined in the header, and then importing the header files defining those classes in source files if needed.
Is there ever a situation in which this wouldn’t be a good idea?
(I know the big disadvantage of forward declaration is the limited usability of an incomplete type. For the purpose of this question, assume that in the header I only need to use the forward-declared class as an incomplete type.)
Sometimes you can change the semantics of the program subtly without raising any errors
Consider the above code and the commented out code lives in a header. If the header is included TestFunction will print 1 otherwise -1