1

Here's my code:

template <class M, class P>
struct SliderMenuItem : rack::ui::MenuItem {
    struct Slider : rack::ui::Slider {
        Slider(M *module) {
            quantity = new P(module);
            box.size.x = 200.0f;
        }
        virtual ~Slider() {
            delete quantity;
        }
    };

    M *pModule;

    SliderMenuItem(M *module, const char *textMenu) : pModule(module) {
        this->text = textMenu;
        this->rightText = RIGHT_ARROW;
    }
};
template <class M, class P>
struct DelaySliderMenuItem : SliderMenuItem<M, P> {
    DelaySliderMenuItem(M *module, const char *textMenu) : SliderMenuItem<M, P>(module, textMenu) {
    }

    Menu *createChildMenu() override {
        Menu *menu = new Menu;
        menu->addChild(new SliderMenuItem<M, P>::Slider(pModule));
        return menu;
    }
};

but it doesn't compile, it says: error: expected type-specifier menu->addChild(new SliderMenuItem<M, P>::Slider(pModule));

What's wrong with this nested class from Parent template access?

markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 1
    `menu->addChild(new SliderMenuItem::Slider(pModule));` -> `menu->addChild(new typename SliderMenuItem::Slider(pModule));` – NathanOliver Mar 31 '23 at 12:47
  • @NathanOliver still doesn't work. It now says "'pModule' was not declared in this scope"... it seems it doesn't inherit the class correctly? – markzzz Mar 31 '23 at 12:51
  • 2
    `this->pModule` – Drew Dormann Mar 31 '23 at 12:52
  • 1
    Woops, forgot you are also trying to access a member from a base class template. To do that you need to use `this` like `menu->addChild(new typename SliderMenuItem::Slider(this->pModule));` That defers lookup until the template is instantiated. – NathanOliver Mar 31 '23 at 12:53
  • [Why do I have to access template base class members through the this pointer?](https://stackoverflow.com/questions/4643074/why-do-i-have-to-access-template-base-class-members-through-the-this-pointer). It's the same issue for both, but the question only refers to accessing data members, not member types. – Yksisarvinen Mar 31 '23 at 12:54

0 Answers0