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.
The answer is YES.
Member functions are operators and functions that are declared as members of a class. Member functions do not include operators and functions declared with the friend specifier. These are called friends of a class. You can declare a member function as static ; this is called a static member function.
Explanation: We can call one function inside another function to access some data of class. A public member function can be used to call a private member function which directly manipulates the private data of class.
Non-member functions are instead declared outside any class (C++ calls this "at namespace scope").
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With