class A{
private:
std::string id;
public:
void f();
};
gives compile time error. However, if I include <string> at top, it compiles correctly. I don’t want to use include statements in headers,though. How can i do it?
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.
You must include
<string>in this case to be able to usestd::string.The only moment when you can avoid #including a header is when you’re only using references or pointers of the object in your header. In this case you can use forward declaration. But since std::string is a typedef, you can’t forward declare it, you have to include it.
I’m sure you’re trying to follow the advice to try to
#includeas less as possible, but you can’t follow it in this case.