15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Container of Containers

Alan J. Livingston -- AlanLivingston@acm.org
Tuesday, November 12, 1996

Environment: NT 3.51 VC++ 4.2b
==============================

Hi All,

If I create a container of pointers to some class using CTypedPtrList:

        CTypedPtrList MyContainer;

I want to create a container that holds pointers to containers:
        CTypedPtrList*>
MyContainerContainer;>
But the compiler balks since CObList has two AddHead functions.  One
takes a
CObList* and returns void.  

When the compiler tries to build the second container of containers, it
tries to create an AddHead function that takes a pointer to a class
derived
from CObList.  Since this form of CObList  returns void, it can't find
the
correct CObList::AddHead function.

Has anyone successfully implemented a CTypedPtrList of CTypedPtrList*
(or
one of the other derivatives.)

-Alan



Rommel Songco -- rsongco@spectrasoft.com
Thursday, November 14, 1996

[Mini-digest: 5 responses]

Hi Alan,

> If I create a container of pointers to some class using CTypedPtrList:
> 
>         CTypedPtrList MyContainer;

I assume that you derived CMyClass from CObject.

> 
> I want to create a container that holds pointers to containers:
>         CTypedPtrList                       CTypedPtrList*>
> MyContainerContainer;>

Here, it is not a good idea to use CObList since the elements to be placed
in your second list are not CObject pointers.  I suggest you use CPtrList
instead.

Hope that helps.

Regards,

Rommel V. Songco
rsongco@spectrasoft.com

-----From: Dave_Rabbers@Quinton-Eng.CCMAIL.CompuServe.COM

     I think you want:
     
     CTypedPtrList  *> 
     MyContainerContainer;
     
     Yes, I've done this sort of thing, but with the CPtrArray classes.
     
-----From: "Alan J. Livingston" 

Environment: NT 3.51, VC++ 4.2b
===============================

Actually I want the container derived from CObList so that it supports
serialization.

I don't see how your solution can even compile.  CPtrList::AddHead has the
same prototype as CObList.  Can you provide me with a code snippet?  I tried
the following and VC++ 4.2b balks:

        #include "afxtempl.h"


        class CMyClass

        {};


        void main ()
        {

	  CTypedPtrList *> BigList;

        }

-Alan

-----From: "Alan J. Livingston" 

Environment: NT 3.51, VC++ 4.2b
===============================

I read your post again and this won't work with a class based on CPtrList,
but _will_ work for CPtrArray.

It works since CPtrArray::InsertAt has different prototypes for inserting a
single element and inserting another array into the current array.  The MFC
designers should have done something similar for the CxxxList classes as well.

I have come to the conclusion that I can't use CTypedPtrList to contain a
list of CTypedPtrList*.

-Alan


-----From: "T.K.Wessing" 

Environment: NT 4.0 VC++ 4.2b

Yes, We have made a couple of these thinks using a class in between them.

try making a class like this:

CTypedPtrList< CObArray, CObject*> m_MyList;

class CMy2ndContainer : public CObject
{
	public: // when I'm testing thinks every thing is public

	// ctor
	// dtor: Make sure you clean up ervery thing


	// add usefull functions like:
	BOOL	AddObject(CObject* theNewObject);
	// ...

	m_MyList m_2ndList ;	
}


func()
{
	m_MyList m_1stList ;	
	CObject *pObj;
	CMy2ndContainer *pList2;
	
	pObj = new CObject ;

	pList2 = new CMy2ndContainer ;

	pList2->AddObject(pObj) ;

	m_1stList.AddObject(pList2);
}
I

/=====================================
|  T.K.Wessing
|  Senior Software Engineer
|  Caledon systems international BV
|  The Netherlands
|  Private E-Mail:
|  tkw@xs4all.nl
\=====================================
The Nedherlands ?
Yep, "The Nedherlands" It does exists indeed!





| Вернуться в корень Архива |