Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Advanced
Oct 14, 1999

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 <string>
  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 <string>
  #include <vector>
  int main()
  {
    using std::string; //using declaration; 
needed only once using std::vector; // using declaration string str; // non-qualified name string str2; vector <int> vi; }
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap