Closed Trree closed 6 years ago
when I using
template<class T> using Width = NamedType<T, struct WidthTag>; template<class T> using Height = NamedType<T, struct HeightTag>; template<class T> class Rectangle { public: Rectangle(Width<double> width, Height<double> height) : width_(width.get()), height_(height.get()) {} ...... }
so in the main.cpp, I have to write this:
Rectangle<double> r(Width<double>(10), Height<double>(12));
when I put it into class:
template<class T> class Rectangle { public: using Width = NamedType<T, struct WidthTag>; using Height = NamedType<T, struct HeightTag>; Rectangle(Width width, Height height) : width_(width.get()), height_(height.get()) {} ...... }
Rectangle<double> r(Rectangle<double>::Width(10), Rectangle<double>::Height<double>(12));
I have a better choice or make it better?
Befora C++17; use a free function to have automatic type deduction In C++17: There is template type deduction for classes
when I using
so in the main.cpp, I have to write this:
when I put it into class:
so in the main.cpp, I have to write this:
I have a better choice or make it better?