Smart pointer, abstract base class
От: Аноним  
Дата: 07.12.05 20:50
Оценка:
Дано:


class CAbstractBase
{
  void foo() = 0;
};

class CConcreteClass : public CAbstractBase
{
  void foo(){};
};

class CConcreteClass2 : public CAbstractBase
{
  void foo(){};
};

//
// smart_ptr - шаблонный класс, некий "умный указатель".
//
CAtlMap< int, smart_ptr< CAbstractBase > > mapList;


CConcreteClass * pConcrete = new CConcreteClass;
smart_ptr< CAbstractBase > spMyPtr( pConcrete );

//
// не помню как называется ф-ция добавления эл-та в CAtlMap, 
// но смысл понятен - добавили переменную в ассоциативный массив
//
mapList.Add( 1, spMyPtr ); 

CConcreteClass2 * pConcrete2 = new CConcreteClass2;
smart_ptr< CAbstractBase > spMyPtr2( pConcrete2 );

mapList.Add( 2, spMyPtr );



Что хотелось бы иметь:


smart_ptr< CConcreteClass > sp; 
mapList.Lookup( 1, sp );

smart_ptr< CConcreteClass2 > sp2;
mapList.Looup( 2, sp2 );


Каким образом это реализовать?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.