using alias for static member functions?

c++, c++11, c++14

Solution

`using` is not the correct tool here. Simply declare your alias (as global if you need to) with `auto baz = &Foo::bar`.

As suggested in the comments, you can also make it `constexpr` to have it available, when possible, at compile-time in constant expressions.

struct Foo {
  static void bar() { std::cout << "bar\n"; }
};

constexpr auto baz = &Foo::bar; 

void test() { baz(); }

int main() 
{
    test();
}

Demo

Problem

Is there a way to alias a static member function in C++? I would like to be able to pull it into scope so that I do not need to fully qualify the name. Essentially something like: ``` struct Foo { static void bar() {} }; using baz = Foo::bar; //Does not compile void test() { baz(); } //Goal is that this should compile ``` My first thought was to use `std::bind` (as in `auto baz = std::bind(Foo::bar);`) or function pointers (as in `auto baz = Foo::bar;`), but that is unsatisfactory because for each function I want to be able to use the alias in, I need to make a separate variable just for that function, or instead make the alias variable available at global/static scope.

Original source