illegal reference to non-static member
I am trying to refer to a cstring mycustompath
from a different class from my current class.
CString test = CBar::mycustompath + _T("executables\\IECapt");
But I got this error instead:
error C2597: il开发者_如何学JAVAlegal reference to non-static member 'CBar::mycustompath' c:\work\b.cpp 14
How to fix this?
This means that mycustompath is a property of a specific CBar object and not a property of the CBar class. You'll need to instantiate a CBar class
CBar* myBar = new CBar();
CString test = myBar->mycustompath + _T("executables\\IECapt");
or reference one you already have or, if mycustompath doesn't vary by CBar object, you can change it to static in the class:
class CBar
{
public:
static CString mycustompath;
}
This indicates that CBar::mycustompath
is not a static member variable of CBar
. You will have to create an instance of CBar
to access it:
CBar bar;
CString test = bar.mycustompath + _T("executables\\IECapt");
精彩评论