Threading Static Templated Member Function In Template Class

Feb 25, 2013 at 3:49pm
I'm kinda stuck on this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <thread>

template <int A> struct X
{
    template <int B>
    static void function()
    {
        std::cout << "function\n";
    }
};

int main(int argc, char **argv)
{
    X<0>::function<1>();  // Compiles OK
    std::thread(X<0>::function<1>).join(); // Error: invalid declaration of ‘X<0>::function<1>’|
    return 0;
}


I tried many different combinations and googled a lot.
Just want to thread the static member function, any fix?

EDIT:
Providing an argument makes it work. Why? How can I avoid having to pass an argument?

EDIT2:
Well I fixed it myself using a lambda instead... Works for me, but still it'd be cleaner if it were possible to directly go through the thread's constructor. Oh well, this will do for now.
Last edited on Feb 25, 2013 at 4:23pm
Topic archived. No new replies allowed.