Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: All
Nov 14, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



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