← All notes
P22: Member Templates
C++Templates
A template inside a template, usually used in constructors,
- Use grass carp and sparrow to initialise the fish class and the bird class (passed in to the constructor)
- T1 first works here because first is a grass carp, which inherits from the fish class; this is also called an up-cast
// for smart pointer
template<class _Tp>
class shared_pte:public _shared_ptr<_Tp>{
...
template<class _Tp1>
explicit shared_ptr(const _Tp1* _p):_shared_ptr<_Tp>(_p){}
}
shared_ptr<Base1>sptr(new Derived1);
- To make constructors more flexible
