Reputation: 6797
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: illegal reference to non-static member 'CBar::mycustompath' c:\work\b.cpp 14
How to fix this?
Upvotes: 2
Views: 25809
Reputation: 76788
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");
Upvotes: 3
Reputation: 34408
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;
}
Upvotes: 6