Is there any option to use std in a header file without using any #include statement? I have a class in a header file as following;
class Sequence{
private:
std::string sequence;
unsigned length;
public:
/* Constructors */
Sequence (void);
Sequence (std::string, unsigned);
Sequence (const Sequence &);
/* Destructor Definition */
~Sequence(){}
/* Overloaded Assignment */
Sequence & operator
= (const Sequence &seq)
{
sequence = seq.sequence;
length = seq.length;
return *this;
}
/* Setter and Getter Functions */
void setSequence(std::string);
void setLength(unsigned);
std::string getSequence(void);
int getLength(void);
};
It is not compiled correctly without including iostream. However, I read some comments in related questions where we should not include libraries AND another header files in a header file. So?
#include <string>. The only time you can get away with avoiding other includes are with forward declarations.std::stringin your interface, it is not equaly good to include it in a source file that's using it, because you will have to make sure it's included every time you use the header. That includes client code.std::stringthen you should include<string>. Also, your include section of the source acts as a kind of documentation about what you depend on and use.