tags:

views:

238

answers:

3

Hello all,

I have this class with an instance method named open and need to call a function declared in C also called open. Follows a sample:

void SerialPort::open()
{
    if(_open)
        return;
    fd = open (_portName.c_str(), O_RDWR | O_NOCTTY ); 
    _open = true;
}

When I try to compile it (using GCC) I get the following error:

error: no matching function for call to 'SerialPort::open(const char*, int)'

I included all the required C headers. When I change the name of the method for example open2 I don't have not problems compiling.

How can I solve this problem. Thanks in advance.

+23  A: 

Call

fd = ::open(_portName.c_str(), O_RDWR | O_NOCTTY );

The double colon (::) before the function name is C++'s scope resolution operator:

If the resolution operator is placed in front of the variable name then the global variable is affected.

unwind
Thank you for the quick answer
jassuncao
+7  A: 

Write ::open instead of open. The :: prefix indicates that the name should be taken from the global scope. (Global namespace? I'm not certain about its exact meaning, to be honest...)

Thomas
+3  A: 

add "::" before open (_portName.c_str(), O_RDWR | O_NOCTTY );