[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

How to scope global functions into a namespace?

Is there any way to scope a header file into a different namespace?  The SDK's I am using -- as well as the Win32 API -- all load their functions into the global namespace.  At this point, it's ridiculously cluttered.  Is there any way to force a header file into a specific namespace so I can get rid of the collisions?  I'd like to scope windows.h if I could, since that one has literally thousands of functions in it.
0
cuziyq
Asked:
cuziyq
1 Solution
 
AndyAinscowCommented:
I don't know about that


>>I'd like to scope windows.h
If you could then doing that is probably a bad idea, better to scope your own global functions.

0
 
Infinity08Commented:
>> so I can get rid of the collisions

What collisions would that be ?
0
 
itsmeandnobodyelseCommented:
>>>> What collisions would that be ?

I assume it is functions like GetObject where a macro turn it to GetObjectA or GetObjectW depending on UNICODE preprocessor settings.

We got rid of such 'collisions' by generally using small letters for the first character of member functions and global functions.

If the GetObject comes from a third party header we added a wrapper for the header (of that third party) like

#ifndef WRAPPER_H
#define WRAPPER_H
#ifdef GetObject
#define GetObject_Defined
#define GetObject_Saved GetObject
#undef GetObject
#endif

// now include the header which has conflicts
#include <thirdparty.h>

#ifdef GetObject_Defined
#define GetObject GetObject_Saved
#undef GetObject_Defined
#undef GetObject_Saved
#endif

#endif

You would include the wrapper.h instead of the thirdparty.h and get rid of the collisions that way.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
cuziyqAuthor Commented:
itsmeandnobodyelse:

Wow . . . that really sucks!  But it's been 3 days and that's the best (only) solution offered, so that must be all there is to it.

Thanks, man.
0
 
AndyAinscowCommented:
>>>Wow . . . that really sucks!  But it's been 3 days and that's the best (only) solution offered, so that must be all there is to it.


Don't forget - the comment you accepted isn't what you asked for   ;-)
0
 
Infinity08Commented:
>> But it's been 3 days and that's the best (only) solution offered,

It's been 2 days since I asked for clarification (http:#23708890), and I haven't had any response, so I can't know whether that's all there is ...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now