Carray doubt
-
Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi
-
Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi
Hi, i had the same problem and it seems to be impossible. i created a lot of instances of my class with 'new' and than i stored the pointers in an CObList or CObArray. This array stores only the pointers, so clean the memory up ('delete pClass') when deleting the array. Dr-Kuulun
-
Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi
Try this:
CArray<CMyClass*,CMyClass*&> m_MyArray;
And to acces any data:CMyClass* Temp = m_MyArray[i]; Temp->DoSomething();
Hope this helps ! Ced -
Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi
You are probably better off using the standardized std::vector class:
std::vector< CMyClass > m_myArray;
... now you can fill the vector e.g. using push_back()... And now you can useCMyClass c = GetDocument()->m_myArray[0];
to access the first data item in the associated document. Hope this helps
My opinions may have changed, but not the fact that I am right.
-
Sorry if this is a silly question, but I'm a little confused. I've got a class MyClass and I want to have a CArray of MyClass objects in the Doc class of my application. Ex: In CMyAppDoc CArray <> m_myArray; My question is. How I have to declare and have acces to the array to touch the values of it directly (by reference) in the view? CMyAppView ????? Best Regards Dr. Pi
I have something similar in one of my projects. class CMyDoc : public CDocument { public: void GetAddressList( CDWordArray *pAddresses ); private: CDWordArray m_arrAddresses; }; void CMyDoc::GetAddressList( CDWordArray *pAddresses ) { pAddresses->RemoveAll(); pAddresses->Append(m_arrAddresses); } void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CMyDoc *pDoc; CDWordArray arrAddresses; pDoc = GetDocument(); pDoc->GetAddressList(&arrAddresses); } Hope this helps, or at least gives you an idea.