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: All
Nov 13, 1998

A Workaround for Namespace-less Compilers

Since namespaces are relatively new in C++, some compilers do not support this feature yet. To workaround this lack of support, you can use struct holding static member functions:
 
struct MY_PROJ{ // hide a function in a struct, rather than inject its name to the global namespace
  static time_t Time() { return time(0); }
}

struct YOUR_PROJ {
  static time_t Time() { return Date::time();} // different function with an identical name 
}
Of course, this workaround does not offer all of the benefits of real namespaces, such as argument dependent lookup, using declaration, and using directive. However, it can be used to avert name conflicts as in the example above.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date