hello. i am having a problem with the this-pointer in the code below. for the command: "MyFunctB(this)"; i am getting the following error: error C2664: 'cTest::MyFunctB' : cannot convert parameter 1 from 'cTest *const ' to 'cTest' whats the problem? thanks. V.K. Code: class cTest { public: cTest() { for (int i=0;i<3;i++) dat[i] = rand()%43; } void MyFunctA () { MyFunctB(this); } void MyFunctB (cTest a) { } private: int dat[3]; }; int main() { int i=0; srand(time(0)); cTest A; A.MyFunctA(); _getch(); return 0; }
Code: void MyFunctA () { MyFunctB(this); [COLOR=Red]'this' is a pointer to a cTest[/COLOR] } void MyFunctB (cTest a) [COLOR=Red]'a' is an actual cTest object[/COLOR] { } Types have to match or be convertible. Why would you pass the 'this' pointer? It's automatically passed implicitly. Now you just have two copies.