What is generally considered good coding style in C++ where you use types from the standard library? For example, if I have a using namespace std;
directive would you still expect to see library types fully qualified like so: std::string
or is it acceptable to just use string
as the type identifier?
If you do fully qualify, can you expain the rationale behind it?
fully qualify in header files. import the namespace in the .cpp files.
keeps the global namespace from being cluttered by a simple #include
I'd prefer using:
using std::string;
string whatever;
than fully bringing the namespace in.
In any case library developers should avoid type names that conflict with the standard ones although string
probably is quite common.
For libraries other than standard I like to qualify if the nesting namespaces is not too long, if it is just typedef it to a meaningful name that includes the library name or something like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With