开发者

Porting C++-code from Windows to Unix: systemcalls colliding with name of functions

I'm porting some crufty C++ Windows-code to Linux, which uses functions called "o开发者_运维技巧pen" 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++?


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜