Sorry about the earlier post, made a mistake there, only the base class non-virtual destructor shall be called, and the overhead will be the extra constructor of the derived class.
2009/11/11 Akanksh Vashisth <[email protected]> > Hello Sumit, > > I would advice against using this form: > > template<class T> class m_signal_out_if<T> : public m_signal_inout_if<T> > {}; > > to do a pseudo-typedef, because here the assumption is that m_signal_inout_if > has a virtual destructor, because if m_signal_inout_if does not have a > virtual destructor, than the destruction of the base class shall not be > correct and might result in memory leaks if any of the base classes free up > allocated memory while destructing. > > So this technique works fine if the base class is known to not do any > allocations (and you are happy with undefined destruction behaviour) or if > it is known that the base class has a virtual destructor. Even so, the > overhead of the compiler generating the constructor and destructor of this > derived class is not acceptable or needed. > > And yes, C++0x will have support for templated typedefs. > > 2009/11/11 Sumit Adhikari <[email protected]> > >> Hello Akanksh, >> I already had a solution through which I could have wrote(in fact I used >> if you see mt other template classes) it as follows : >> template<class T> class m_signal_out_if<T> : public >> m_signal_inout_if<T> {}; >> But I was curious about this specific implementation of templated typedef. >> Well it is not supported. I do know it is supported in c++0x. >> Thanks for the reply, >> Regards, >> Sumit >> >> >> >> On Wed, Nov 11, 2009 at 2:37 PM, Akanksh Vashisth >> <[email protected]>wrote: >> >>> Also, if a collection of such typedefs is needed, something like this can >>> be done ( but I would not suggest it as a default solution ) >>> >>> template<typename T> >>> struct MyType >>> { >>> typedef m_signal_inout_if < T > m_signal_out_if; >>> typedef something_else_01<T> something_01; >>> typedef something_else_02<T> something_02; >>> } >>> >>> and these can now be used as: >>> >>> MyType<SomeType1>:: m_signal_out_if variable_name_01; >>> MyType<SomeType2>:: something_01 variable_name_02; >>> MyType<SomeType3>:: something_02 variable_name_03; >>> >>> Hope this helps. >>> >>> Akanksh Vashisth >>> Graphics Engine Programmer >>> ArtVPS Ltd. >>> Cambridge, UK >>> >>> 2009/11/11 Akanksh Vashisth <[email protected]> >>> >>> Hello Sumit, >>>> >>>> In C++ typedef of a template is illegal, so the following code >>>> >>>> >>>> template < class T > >>>> typedef m_signal_inout_if < T > m_signal_out_if < T > ; >>>> >>>> will not compile. >>>> >>>> If you do want to typedef something like this, you need to surround it >>>> with a class definition, such as: >>>> >>>> template<typename T> >>>> struct m_signal_out_if >>>> { >>>> typedef m_signal_inout_if < T > type; >>>> } >>>> >>>> This can now be used as a type in the following way: >>>> >>>> m_signal_out_if<SomeType>::type variable_name; >>>> >>>> But seeing that the difference in you typedef name and the original >>>> class name is not a lot, the overhead and complexity of this typedef is (in >>>> my opinion) not acceptable. >>>> >>>> Hope this helps. >>>> >>>> Akanksh Vashisth >>>> Graphics Engine Programmer >>>> ArtVPS Ltd. >>>> Cambridge, UK >>>> >>>> 2009/11/11 Sumit Adhikari <[email protected]> >>>> >>>> A little correction : >>>>> >>>>> # ifndef M_SIGNAL_OUT_IF_H_ >>>>> # define M_SIGNAL_OUT_IF_H_ >>>>> >>>>> >>>>> # include "m_signal_inout_if.h" >>>>> >>>>> template < class T > typedef m_signal_inout_if < T > m_signal_out_if >>>>> < T > ; >>>>> >>>>> >>>>> >>>>> # endif /*M_SIGNAL_OUT_IF_H_*/ >>>>> >>>>> >>>>> >>>>> -------------------------------------------- >>>>> Sumit Adhikari >>>>> System Design Engineer >>>>> austriamicrosystems AG >>>>> Business Unit : Automotive >>>>> Mob : 00-91-9885271710/00-91-9000161710 >>>>> >>>>> >>>>> >>>>> On 11/11/2009 8:49 AM, Sumit Adhikari wrote: >>>>> >>>>>> Hello All, >>>>>> >>>>>> I have a template class like as follows : >>>>>> >>>>>> # ifndef M_SIGNAL_INOUT_IF_H_ >>>>>> # define M_SIGNAL_INOUT_IF_H_ >>>>>> >>>>>> # include "m_signal_in_if.h" >>>>>> >>>>>> template < class T > class m_signal_inout_if : public m_signal_in_if < >>>>>> T > { >>>>>> public : >>>>>> virtual void write (const T&) = 0 ; >>>>>> virtual void initialize(const T&) = 0; >>>>>> }; >>>>>> >>>>>> >>>>>> # endif /*M_SIGNAL_INOUT_IF_H_*/ >>>>>> >>>>>> I want to declare typedef of m_signal_inout_if and I have done it as >>>>>> follows : >>>>>> >>>>>> # ifndef M_SIGNAL_OUT_IF_H_ >>>>>> # define M_SIGNAL_OUT_IF_H_ >>>>>> >>>>>> >>>>>> # include "m_signal_inout_if.h" >>>>>> >>>>>> template < class T > m_signal_inout_if < T > m_signal_out_if < T > ; >>>>>> >>>>>> >>>>>> # endif /*M_SIGNAL_OUT_IF_H_*/ >>>>>> >>>>>> >>>>>> But I am getting syntax error in this process. >>>>>> Can anybody please tell me what is the wrong with it ? >>>>>> Regards, >>>>>> >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Help-gsl mailing list >>>>> [email protected] >>>>> http://lists.gnu.org/mailman/listinfo/help-gsl >>>>> >>>> >>>> >>> >> >> >> -- >> >> -------------------------------------------- >> Sumit Adhikari >> System Design Engineer >> austriamicrosystems AG >> Business Unit : Automotive >> Mob : 00-91-9885271710/00-91-9000161710 >> > > _______________________________________________ Help-gsl mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-gsl
