Friday, May 21, 2010

Multiple Classes in C++?

Suppose that myprog.cpp is a client of three classes, class1 (with files class1.h class1.cpp), class2 (with files class2.h, class2.cpp) ,and class3 (with files class3.h class3.cpp). class2 also uses class3 in its code.





Which file(s) must #include the file class3.h?


If class2.h changes, which files must be recompiled?





Would the first just be class3.cpp and class2.cpp (since the third is included in both main and class 2??)


And if class2.h changes, would it be main.cpp and class2.cpp??





thanks!

Multiple Classes in C++?
Any file that uses the implementation for class3 must include class3.h. If only the main.cpp uses the implementation of the three classes then it is the only one (aside from the class itself) that needs to include the header file.





If class2.h file changes then any other file that depends on it will have to be resompiled. If class3 does not use it then it will not recompile.


No comments:

Post a Comment