variadic templates with template function names

前端 未结 5 1106
悲哀的现实
悲哀的现实 2021-01-14 18:14

following this question , I am trying to avoid copy-pasting some code related to calling all of the same-named methods of the mixins of the class BaseSensor.

5条回答
  •  执念已碎
    2021-01-14 19:06

    If you can use c++1z fold expressions would probably be the shortest way:

    template
    class BaseSensor : public SensorType ... //to my BaseSensor class
    {
    public:
        void update() { (SensorType::update(),...); }
        void printStats() { (SensorType::printStats(),...); }
    };
    

提交回复
热议问题