0
두 클래스가 있습니다.두 번째 클래스 멤버 함수에서 first class 멤버 함수를 thread C++ 11에서 호출하는 방법
class first
{
public:
int sum (int a, int b)
{
return a+b;
}
};
class second
{
private:
std::thread t1, t2;
int sum (int a, int b, int c)
{
return a+b+c;
}
public:
void execute()
{
t1 = std::thread (&second::sum, this, 10,20,30); //calling same class function
t2 = std::thread (&first::sum, /*what will be here*/, 10,20); // trying to call another class function
}
};
int main()
{
second s;
s.execute();
return 0;
}
내가 대신 전달해야 무엇/* 여기에 무슨 */
당신은first
의 인스턴스 (또는 적어도 오래 살 것이다
first
인스턴스에 대한 포인터를 필요
당신은 내가 클래스 초에 첫 번째 클래스의 인스턴스를 만들 필요가 말하는 의미를? –
@DeveshAgrawal 네, 'add'는 비 정적 멤버 함수입니다. 따라서'first'의 인스턴스가 필요합니다. – juanchopanza
'std :: thread' [does not] (https://stackoverflow.com/a/21066704/241631)는'reference_wrapper '를 특별히 처리합니다. 조나단의 대답 위에 케이시의 긴 설명을 참조하십시오. – Praetorian