Question

I am new to C++... So, this question might be silly...

I do have, for example, the following struct

template<typename _TpIn, typename _TpOut>
struct TypesKernel {
    typedef _TpIn input_type;
    typedef _TpOut output_type;
};

And now I want to use it within templates. For example:

template<typename _TypesKernel>
class A {
    typedef typename _TypesKernel::input_type input_type;
    typedef typename _TypesKernel::output_type output_type;
    ....
};

Is it possible to somehow avoid this typedef duplications for any class I want to use TypesKernel with?

Thank You in advance!

Was it helpful?

Solution

If you need the typedefs there, the only way I see them included is to either define as you do or inherit from something. Your class might use TypesKernel as base class, or they both could use a common base class that has nothing but the typedefs. (like in std:: framework for iterators).

However inheriting is not necessarily better, you might live with the duplication in many cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top