Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can we derive from the CList? If yes then how?
I tried following thing but I am getting the compile time error.
C++
class IIS_CList : public CList<cobject,>
{
...
}

I am not able to derive it from CList. How should we do it?

[Update]
thank you,

i followed what you said.

if i want to do this in generic way then what should we do for that?
means if i dont know whether the type is int, CString or may other
[/Update]
Posted
Updated 5-Sep-11 0:43am
v4

1 solution

Yes, you may (of course) derive from CList, however the CList class as the following 'template signature' (see CList documentation[^]):
C++
template< class TYPE, class ARG_TYPE = const TYPE& > 
class CList : public CObject


Hence you should derive from accordingly, for instance
C++
class MyList : public CList <int, int >
{
  // ...
};


is allowed.

[Update]
If you want the same generality of the CList, in your class, then use:
C++
template  <class TYPE, class ARG_TYPE = const TYPE&> 
  class MyList : public CList < TYPE, ARG_TYPE  >
  {
    //..
  };

[/Update]
 
Share this answer
 
v6
Comments
Eugen Podsypalnikov 5-Sep-11 6:34am    
...it is also comfortable to use a type predefinition, for example :) :
typedef CList<int, int> CIntEntries;
class CMyRegs : private CIntEntries
{
..
void Reset() {
//.. some leaving actions
//..
CIntEntries::RemoveAll();
}
};
sunnyram 5-Sep-11 6:36am    
thank you,

i followed what you said.

if i want to do this in generic way then what should we do for that?
means if i dont know whether the type is int, CString or may other

then what should we do for this
class MyList : public CList <cobject,cobject>
{
// ...
};
can we do like this?

i tried this i got the error like:
cannot access protected member declared in class 'CObject'
Eugen Podsypalnikov 5-Sep-11 6:41am    
An int is not a CObject yet... :)
But you can control for example the VARIANTs in your list
or the pointers of CMyGenericValueBase. Then you could dirive some real values, for example CMyString : public CMyGenericValueBase and others... :)
sunnyram 5-Sep-11 6:48am    
thank you

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