devxlogo

Avoid Excessive use of Fully Qualified Names

Avoid Excessive use of Fully Qualified Names

To some extent, the use of fully qualified names is the recommended way of referring to namespace members because it uniquely identifies and yet it avoids name conflicts. For example:

   #include   int main()  {    std::string str;    std::string str2;  }

In the example above, the fully qualified name std::string is used twice. In real world code, however, dozens of components of the Standard Library are used. Repeating their qualified names over and over again is laborious and error-prone. Worse yet, it renders your code unreadable. When you need to use qualified names more than 2-3 times, prefer a using-declaration or even a user-directive:

   #include   #include   int main()  {    using std::string; //using declaration; 
needed only once using std::vector; // using declaration string str; // non-qualified name string str2; vector vi; }

devx-admin

Share the Post: