McLovin
McLovin

Reputation: 3415

Alias in class method and global function

I'm trying to encapsulate winsock2 inside a class, and I have this member function called bind, which obviously bumps into winsock2.h 's bind function.

class foo {
public:
  void bind();
  void some_function() {
    bind(_sockfd, p->ai_addr, p->ai_addrlen); //error... compiler actually calls foo::bind() instead of the global bind function.
  }

private:
  ...
}

Is there a solution for this? (aside from renaming foo::bind()).

Upvotes: 1

Views: 57

Answers (1)

mksteve
mksteve

Reputation: 13085

If the function you require is NOT a macro, then you can fully qualify it.

class base {
      int bind(...);
}

class derived : public base {
       int bind(...);
       int someFunction();
}


int derived::someFunction()
{
      base::bind(); // call base class's implementation.
      bind();  // call derived::bind();
      ::bind();  // call global function.
}

Upvotes: 1

Related Questions