Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i havae created CTypedPtrArray like
CTypedPtrArray<CObArray,COverLayItems*> myArray;

in the document class in MFC where "COverLayItems" is serializable class created by me. Now i need to access this array(myArray) from other classes because it is declared as private i have to write some member functions for getting and setting this array.
please help me for that..
how i can return this myArray by reference...

Thanks in advance
Posted
Updated 9-May-11 19:10pm
v2
Comments
Albert Holguin 10-May-11 13:33pm    
why do you want to return be reference a private array? that has the same effect as making it public (unless you return it as const)

1 solution

A possible way :) :

// yours.h

typedef CTypedPtrArray<CObArray,COverLayItems*> CItems;

class C
{
  CItems m_cItems;
..
public:
..
  CItems& GetItems() const { return m_cItems; }
  // const CItems& GetItems() const { return m_cItems; }
..
};
 
Share this answer
 
v2
Comments
sandeepnayathil 10-May-11 3:12am    
when accessing this get function from other class, i have another error

'CObject::operator =' : cannot access private member declared in class 'CObject'

i added copy constructor and assignment operator overloaded function in my class derived from cobject(ie COverLayItems) but still this problem remains
Eugen Podsypalnikov 10-May-11 3:45am    
Please post the code line of the error here :)
sandeepnayathil 10-May-11 4:21am    
CImage_ExplorerDoc* doc = (CImage_ExplorerDoc*)pFrame->GetActiveDocument();
// This is an array to store co-ordinate values and other properties of shapes.
CTypedPtrArray <cobarray,coverlayitems*> myArray = doc->GetItems();
// i accessed that getitems() from another class
Eugen Podsypalnikov 10-May-11 4:27am    
Please try it :) :
CTypedPtrArray <cobarray,coverlayitems*>& myArrayRef = doc->GetItems();
sandeepnayathil 10-May-11 4:34am    
That also not working
'cannot convert CTypedPtrArray<BASE_CLASS,TYPE> to CTypedPtrArray<BASE_CLASS,TYPE>&'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900