threads start for class methods: Why i need both Class&object's addresses?

If i want to thread a method class rather than a function

I need to pass as arguments both the method class address and my object's address. BUT not the object's method address at all! Why?

1
2
3
4
5
6
7
8
9
10
11
12
class X
{
public:
void printX() 
     { cout<<"100"<<endl;}
};

int main()
{
X my_x;
thread t(&X::printX, &my_x);
}


While the following wouldnt compile:
 
thread t2(my_x.printX);


I cant handle method classes directly like functions with threads eh?
Why whats the special about it?

I would like the Theorytical background on why we need their addresses first, BOTH addresses especially

Hope I couldn't set it more clear - Thank You
Last edited on
Well, if you didn't have the function's address, you wouldn't be able to call it.

Since the function is not a static member function, you need an object to call it with, which is why you are passing the object as well.

If you could do like you asked, that would basically amount to passing both the object and the function pointer anyway, which is what you are doing in the end.
Thank you.

Just for a spherical view :
Is there any other area where we do this, using both the object address and the method class address to use-call the method?
Topic archived. No new replies allowed.