in his book Effective C++, Scott Meyers claims that including header files creates a dependency between the two entities. Furthermore, he claims that if main depends on Employee.h and Employee.h depends on Date.h, the dependency works all the way through the dependencies in such a way that if Date changes, all will have to recompile.
A solution for this kind of situation is the pimpl-idiom (pointer to implementation). The Employee class doesn't have a Date-object, it has a pointer (smart or otherwise) to EmployeeImpl-class object. The EmployeeImpl carries all of the implementation details and Employee-class objects merely forward methods calls to the implementation-class' methods.
This is all clear to me. My problem right now is that I suspect this isn't true. There is no need for recompilation if Date is changed. I created a simple test and the result was that Employee-object never needed recompilation and in fact, neither did main.o. Only Date-class was recompiled after it was changed and after that the three object-files were linked. This is exactly what was suppose to happen were I to have used the pimpl-idiom.
Has Scott Meyers made a mistake? Does GCC do things differently? Jupiter facing Mars again :) ?
PS. The source used for this test is included in its original form without the modifications made to Date-class.


Sign In
Create Account



Back to top









