Problem with public variables
-
I declared a variable through ClassView>Add Member Variable in my Cview. I included header in my MainFrm.cpp. How to use the variable because it doesnt recognise my variable. Do I need to make an object inside my MainFrm.cpp? I tried to use CProgView cview; cview.myvariable; but it says cannot access protected member declared in class. Thanks
-
I declared a variable through ClassView>Add Member Variable in my Cview. I included header in my MainFrm.cpp. How to use the variable because it doesnt recognise my variable. Do I need to make an object inside my MainFrm.cpp? I tried to use CProgView cview; cview.myvariable; but it says cannot access protected member declared in class. Thanks
-
Thx Astham There are 3 kinds of member variables/functions: public: Can be used/called by objects of any class private: Can be used by objects of this class only protected: Can be used by objects of this class and derived classes only. So if you want to use the variable from somewhere else than a CProgView member function, you need to make the variable public. If you use Add Member Variable there's three radio buttons at the bottom of the dialog. Or you could just write public: at the line before the variable declaration. THis is my header code,
// Implementation
public:
float pointX[100];
float pointY[100];
virtual ~CMyProgView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif] This is my public variable declaration. Why cant I use it? How to use it from my CMyProgDoc? I have #include CMyProgView.h and use it such as below: CMyProgView obView; obView.pointX[i] = something;