|
-
March 31st, 1999, 09:44 AM
#1
Cannot Acces Private member
Here is my situation:
class CFilterTab : public CDialogBar
{
private:
CTypedPtrArray<CObArray,CDialog*> m_DlgArray;
};
void CReponseFilterTab::CreatePages()
{
CDialog* dlg;
dlg = &dlgStudent;
ASSERT(dlg);
m_DlgArray.Add(dlg);
VERIFY(dlg->Create(IDD_STUDENT,&m_tabcontrol));
dlg = &dlgDate;
ASSERT(dlg);
m_DlgArray.Add(dlg);
VERIFY(dlg->Create(IDD_DATE,&m_tabcontrol));
dlg = &dlgLesson;
ASSERT(dlg);
m_DlgArray.Add(dlg);
VERIFY(dlg->Create(IDD_LESSON,&m_tabcontrol));
dlg = &dlgChoice;
ASSERT(dlg);
m_DlgArray.Add(dlg);
VERIFY(dlg->Create(IDD_CHOICE,&m_tabcontrol));
}
I get these errors:
K:\projet2\VRUtilities\ReponseFilterTab.cpp(50) : error C2248: 'm_DlgArray' : cannot access private member declared in
class 'CFilterTab'
k:\projet2\vrutilities\filtertab.h(18) : see declaration of 'm_DlgArray'
K:\projet2\VRUtilities\ReponseFilterTab.cpp(56) : error C2248: 'm_DlgArray' : cannot access private member declared in
class 'CFilterTab'
k:\projet2\vrutilities\filtertab.h(18) : see declaration of 'm_DlgArray'
K:\projet2\VRUtilities\ReponseFilterTab.cpp(61) : error C2248: 'm_DlgArray' : cannot access private member declared in
class 'CFilterTab'
k:\projet2\vrutilities\filtertab.h(18) : see declaration of 'm_DlgArray'
K:\projet2\VRUtilities\ReponseFilterTab.cpp(66) : error C2248: 'm_DlgArray' : cannot access private member declared in
class 'CFilterTab'
k:\projet2\vrutilities\filtertab.h(18) : see declaration of 'm_DlgArray'
K:\projet2\VRUtilities\ReponseFilterTab.cpp(75) : error C2248: 'm_DlgArray' : cannot access private member declared in
class 'CFilterTab'
k:\projet2\vrutilities\filtertab.h(18) : see declaration of 'm_DlgArray'
I realize I cannot access a private member. But I'm not sure how to create a function in CFilterTab that will return my
m_DlgArray.
Need some assistance
CTypedPtrArray<CObArray,CDialog*> CFilterTab::GetArray()
{
return m_DlgArray;
}
Can I do this? I've tried and I get this error:
K:\projet2\VRUtilities\FilterTab.cpp(127) : error C2558: class 'CTypedPtrArray<class CObArray,class CDialog *>' : no
copy constructor available
Thank you in advance for your help
-
March 31st, 1999, 09:54 AM
#2
Re: Cannot Acces Private member
Try returning the address of the array instead of a copy of the array, I think the function will look like:
CTypedPtrArray* CFilterTab::GetArray()
{
return &m_DlgArray;
}
-
March 31st, 1999, 09:55 AM
#3
You're almost there
Just change the declaration of CFilterTab::GetArray() to return a reference, and then you can use the return from that to access m_DlgArray. Good luck.
-
March 31st, 1999, 10:17 AM
#4
Re: Cannot Acces Private member
I've done that and I don't get the copy error anymore. Thank you!
CTypedPtrArray<CObArray,CDialog*>* CFilterTab::GetArray()
{
return &m_DlgArray;
}
But now how do I access it in this code:
void CQuestionFiltertab::CreatePages()
{
CDialog* dlg;
dlg = &dlgLesson;
ASSERT(dlg);
m_DlgArray.Add(dlg); //problem with this code
VERIFY(dlg->Create(IDD_LESSON,&m_tabcontrol));
char str[50];
TC_ITEM tci;
tci.mask = TCIF_TEXT;
tci.iImage = -1;
for(int i=0; i<NUM_PAGES; i++)
{
dlg = m_DlgArray[i];
dlg->GetWindowText(str,sizeof(str));
tci.pszText = str;
m_tabcontrol.InsertItem(i, &tci);
dlg->ModifyStyle(WS_CAPTION,0);
dlg->SendMessage(WM_NCACTIVATE,TRUE);
}
}
I've tried the normal
CTypedPtrArray<CObArray,CDialog*>* array = GetArray();
array.Add(dlg);
error I get are:
K:\projet2\VRUtilities\QuestionFiltertab.cpp(36) : error C2228: left of '.Add' must have class/struct/union type
And if I try
CTypedPtrArray<CObArray,CDialog*> array = GetArray();
array.Add(dlg);
I get the error:
K:\projet2\VRUtilities\QuestionFiltertab.cpp(35) : error C2440: 'initializing' : cannot convert from 'class
CTypedPtrArray<class CObArray,class CDialog *> *' to 'class CTypedPtrArray<class CObArray,class CDialog *>'
No constructor could take the source type, or constructor overload resolution was ambiguous
Thank you for your help in advance
-
March 31st, 1999, 10:22 AM
#5
Re: Cannot Acces Private member
You were close, try:
CTypedPtrArray* array = GetArray();
array->Add(dlg);
-
March 31st, 1999, 10:57 AM
#6
Re: Cannot Acces Private member
One Last question:
How about this part?
for(int i=0; i<NUM_PAGES; i++)
{
dlg = m_DlgArray[i];
}
Thank you
-
March 31st, 1999, 11:11 AM
#7
Re: Cannot Acces Private member
not sure offhand, but I guess you'll need something like:
for(int i=0; i<NUM_PAGES; i++)
{
dlg = m_DlgArray->GetItem(i);
}
(you'll need to check if the GetItem function is the right one for the CTypedPtrArray)
-
March 31st, 1999, 04:03 PM
#8
Re: Cannot Acces Private member
Dear Sophie,
This is probably a dumb question, but should
void CReponseFilterTab::CreatePages()
be
void CFilterTab::CreatePages()?
It seems that
void CReponseFilterTab::CreatePages()
is in a different class from the array, and therefore cannot get at the private member.
If CResponseFilterTab derives from CFilterTab, then you might make the array protected instead of private. Then derived classes can get at it, but not outsider classes.
Yours,
Wes Rogers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|