Reputation: 198
I'm writing a simple socket C++ class and it looks like this:
class Socket {
public:
// ...
void connect();
private:
// ...
int socket;
};
There are two issues with my class:
void Socket::connect()
I'm using the native Linux socket interface, which means there is already a function called int connect(...)
that I want to use inside the Socket::connect()
function.
int socket
Same problem. The class variable name has a conflicting name with the int socket(...)
function.
Question: Am I forced to change the name of the int socket
and void connect()
to something else, or is there a workaround?
Upvotes: 0
Views: 487
Reputation: 206747
The global names can be used by using the global scoping operator, ::
.
Inside the class, you can use ::connect
and ::socket
to use the global functions. To call the global functions, use ::connect(...)
and ::socket(...)
.
Upvotes: 6