8000 应用层,类的非静态函数不能使用,目前仅静态函数可用 · Issue #38 · mtrebi/thread-pool · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
应用层,类的非静态函数不能使用,目前仅静态函数可用 #38
Open
@dbdxnuliba

Description

@dbdxnuliba

测试例程如下:
class A {
public:
static int Afun(int n = 0 57B2 ) {
std::cout << n << " hello, Afun ! " << std::this_thread::get_id() << std::endl;
return n;
}

void Cfun(void) {
    std::cout <<  "  hello, Cfun !  "<< "mem_a :"<<mem_a <<"  " << std::this_thread::get_id() << std::endl;
    return ;
}

private:
int mem_a=0;
};
void test_thread_pool()
{
// Create pool with 3 threads,max_thr_num:100
//同时存活的线程的最小数量3,同时存活的线程的最大数量100
ThreadPool pool(1,2);

// Initialize pool
pool.init();

std::cout << "main thread id :"<<std::this_thread::get_id()<< std::endl;

 std::future<int> gg = pool.submit(A::Afun, 9999);//静态函数成功
 A A_obj;
std::future<int> hh = pool.submit(A_obj.Cfun,); //非静态函数不成功

}

: error: invalid use of non-static member function
std::future hh = pool.submit(A_obj.Cfun);
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0