Chained conversion between classes without public inheritances

后端 未结 2 1977
挽巷
挽巷 2021-01-16 12:54

Question

I have a series of ~10 template classes A, B, C, D, ...

I want to enable conversions from a class to previous classes in the series

2条回答
  •  迷失自我
    2021-01-16 13:24

    You can achieve this by constraining a templated constructor (which will be used in conversion) using std::enable_if and some template metaprogramming:

    template