1

I want to write a C++ wrapper for the Linux Socket API. The method of my wrapper should have the same names as the underlying function names of the API.

But for example in the bind() method I use the plain C bind() function from the Linux socket API. I call bind(mSocketDescriptor, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) which is compatible with the signature of the APIs function. My compiler is complaining Invalid arguments 'Candidates are: bool bind(int)' Which is referring to my method inline bool Socket::bind(int portno).

Why is Eclipse referring to the wrappers function and how do I inhibit Eclipse doing this?

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103

2 Answers2

2

You must add a global scope qualifier:

::bind(mSocketDescriptor, (struct sockaddr *) &serv_addr, sizeof(serv_addr));

The scope resolution determines, where the compiler looks for a name. You can prefix a name with a namespace and/or class scope (e.g. socket_wrapper::socket::bind()). And there is the global scope, where the system functions usually live. These functions may be prefixed with the global scope qualifier ::bind(), so the compiler knows not to use a local method with the same name.

There is also the std namespace, where the classes and functions of the standard library are located. If you want to use the standard library, you prefix these names with std:: (e.g. std::iostream, std::cout, std::string, std::vector<>, ...).

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
0

Use namespaces please. Explicitly !

Also, C calls should be referred with :: prefix ::bind in your case

GregJaskiewicz
  • 456
  • 3
  • 11