I was working with xemacs in unix. One of my c++ class header file has a string variable. E.g.:
document.h:
Notice the #include <string>. I had to place that or else the compiler doesnt recognize the string variable. Why is it so? I never had to do that in VC++. Can't i just include the string header before this header file in the implementation file?Code:#ifndef DOC_H #define DOC_H #include <string> using std::string; class Document { public: /* ... */ private: String name; }; #endif
E.g:
document.cpp:
Code:#include <iostream> #include <string> #include "document.h" using namespace std; /*.........Implementations of class document....*/



LinkBack URL
About LinkBacks



But i must warn you, never to use a using-stament in header-files. Its a real bad habit, because you force every user of your header/lib to live together with your using-statement. Its much better to always use the complete "path" in your header, for example std::string, std::vector an so on. Use using-statments only in cpp-files.