To understand the difference, you must understand why the compiler needs to be turned on first.
The compiler must know the size of each class you declare. Thus, he must know the size of each member added to the class. In the case of a non-pointer non-inline member, the compiler should see the definition of this member class, which is usually in the header that you should include. In the case of a pointer, however, the compiler does not need to see the whole definition, because, regardless of its type, the pointer always has the same size on this platform (usually 32 or 64 bits). Therefore, when an element is a pointer, the compiler needs to know only the name, which can be executed by direct declaration, i.e.
class AnotherClass;
Now which one to use?
Shortcut: Use forward ad whenever you can, enable when you need to.
If your headline can do a great job ad forward, you will reduce the total compilation time because every heading you include must be handled in every translation unit that contains it.
The general scheme is to forward the declaration in the header and include the corresponding class in the associated .cpp .
source share