Click to See Complete Forum and Search --> : Cannot Acces Private member


Sophie
March 31st, 1999, 08:44 AM
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

MikeL
March 31st, 1999, 08:54 AM
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;

}

Bore
March 31st, 1999, 08:55 AM
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.

Sophie
March 31st, 1999, 09:17 AM
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

MikeL
March 31st, 1999, 09:22 AM
You were close, try:


CTypedPtrArray* array = GetArray();

array->Add(dlg);

Sophie
March 31st, 1999, 09:57 AM
One Last question:

How about this part?

for(int i=0; i<NUM_PAGES; i++)

{

dlg = m_DlgArray[i];

}


Thank you

MikeL
March 31st, 1999, 10:11 AM
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)

Wes Rogers
March 31st, 1999, 03:03 PM
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