c++ - Can't access private class members inside of static method? -


i have following setup:

//.h class cell { private:     point   mcellstartingpoint;     int     mxoffset;     int     myoffset; public:     static void drawrowofpixels(int yoff);     cell();     ~cell(); };  //.cpp void cell::drawrowofpixels(int yoff) {     hdc dc = getdc(null);     colorref red = 0xff0000;     for(int = mcellstartingpoint.x; < mxoffset; i++)     {         setpixel(dc, mcellstartingpoint.x + i, mcellstartingpoint + yoff, red);     } } 

however, when implementing drawrowofpixels() method in .cpp file, errors @ of member variables of cell class. (i.e. mcellstartingpoint, mxoffset, , myoffset)

error c2228: left of '.x' must have class/struct/union

error c2597: illegal reference non-static member 'cell::mxoffset'

error c3867: 'cell::mxoffset': function call missing argument list; use '&cell::mxoffset' create pointer member

error: nonstatic member reference must relative specific object

i know i'm doing stupid, what's going on here? why can't use private member variables inside static member function should able to?

you cannot access non static member inside static method unless explicitly make available object instance inside member function.(pass object instance explicitly argument or use global instance can accessed inside function)

for non static member function implicit this pointer passed first argument function. this pointer dereferenced inside member function access members. static members not passed implicit this pointer cannot access non static members inside function unless explicitly object inside member function.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -