views:

80

answers:

3

Hi

I'm porting some crufty C++ Windows-code to Linux, which uses functions called "open" and "close" inside every class... Very bad style, or? Luckily that wasn't a problem in windows, since their systemcalls are named different.

When I try to call the systemcalls open() or close() I'm getting some compiler error about "no matching function for call for class:open()". I can't rename all our functions named "class::open" and "class::close" in the whole code, and I have to use open() and close() since I'm working with serial ports.

So my question is: How can I tell the compiler, which open I mean? How can I escape or hide the namespace of a class in C++?

+7  A: 

You can use ::open to refer to the open in the global namespace.

KennyTM
Thanks! You where the first, so I'm marking your answer -- but it was a close race!
marvin2k
+1  A: 

You can use the scope resolution operator to indicate the global variants ::open and ::close.

Michael Aaron Safyan
+1  A: 

Calling ::open() will call the global function - i.e. the system call.

anon