0

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!

Nik Ved
  • 168
  • 2
  • 8
  • 1
    A remark about naming: names which begin with an underscore followed by an uppercase letter (among others) are reserved to the implementation. (You could rename `_TpIn` to `TpIn_` for example.) As concerns the question: I often see code like that (but see answers below). – gx_ Jun 24 '13 at 10:26
  • Well, I took it from std, but may be it is not a good example... =))) – Nik Ved Jun 24 '13 at 10:34
  • Ah I see :) well names in `std` are considered "implementation" so they have the right – gx_ Jun 24 '13 at 10:46

1 Answers1

1

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.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
Balog Pal
  • 16,195
  • 2
  • 23
  • 37