Hi all,
I have class CTestView and CChartDlg , I want to use an array of CTestView in the other class, here is the code:
Code:
class CTestView : public CView
{
...........................
public:
int num[10]
void fun();
...................................
};
.........................
void CTestView::fun()
{
................
for (int i=0;i<10;i++)
num[i]=i;
.........
}
the other class:
Code:
class CChartDlg : public CDialog
{
public:
CChartDlg(CWnd* pParent = NULL);
.......................
protected:
afx_msg void OnCreate();
.........................
}
...............................
void CChartDlg::OnCreate()
{ ...............
// I want to use num[0]~num[9] in this function.
}
I want to use num[0]~num[9] in class CChartDlg
I tried CCentriodView getv;
but getv.num[0] is not the right num ,can anyone help me with this?Thank you !
Last edited by Angela2010; December 27th, 2011 at 05:21 AM.
I want to use num[0]~num[9] in class CChartDlg I tried CCentriodView getv;
but getv.num[0] is not the right num ,can anyone help me with this?
What the try does mean? You defined getv in the function? Of course it won't work, as you need to access already existing view object, but you create a new one.
So, to make the object be accessible in another object you need to pass the object address (pointer) to that other object. BTW, if I get this correct, you already should have the view pointer in the dialog as dialog parent. If so,
Code:
void CChartDlg::OnCreate()
{
CTestView* pView = (CTestView*)GetParent();
// I want to use num[0]~num[9] in this function.
int num0 = pView->num[0];
}
Bookmarks