I have a class Foo with a corresponding .h and .cpp. Both files make use of an std::string. Should I only #include <string> in the header or include it in both files?
I have a class Foo with a corresponding .h and .cpp. Both files make
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if the header can get away with a forward declaration then I always use that in the header and the #include in the implementation file. (FD can be used for reference and pointer types).
If they both need it, then i tend to put them in both so that if the header is changed I can remove it from the .h.