F
Fei Liu
In Accellerated C++, the author recommends that in a header file one should
not declare
using std::string, using std::vector etc instead one should directly specify
the namespace specifier in code.
for example, this is bad practice:
header.h
#include <string>
using std::string;
class a{
string x;
};
instead, one should write:
#include <string>
class a{
std::string x;
};
The reason given by the author is that 'using std::string' actually pollutes
the scope where 'using std::string' is declared.
I find this style is rather inconvenient when I want to experiment with
different implementation of certain classes in large projects. For example,
I may want to try myns::string or john::string, it's actually much easier to
replace 'using std::string' to 'using myns::string' and instantly switch to
another string implementation. This is much better than going through all
the instances of 'std::string variable' and replace them to 'myns::string
variable'.
What are your thoughts on this coding style?
not declare
using std::string, using std::vector etc instead one should directly specify
the namespace specifier in code.
for example, this is bad practice:
header.h
#include <string>
using std::string;
class a{
string x;
};
instead, one should write:
#include <string>
class a{
std::string x;
};
The reason given by the author is that 'using std::string' actually pollutes
the scope where 'using std::string' is declared.
I find this style is rather inconvenient when I want to experiment with
different implementation of certain classes in large projects. For example,
I may want to try myns::string or john::string, it's actually much easier to
replace 'using std::string' to 'using myns::string' and instantly switch to
another string implementation. This is much better than going through all
the instances of 'std::string variable' and replace them to 'myns::string
variable'.
What are your thoughts on this coding style?