S
S
syxme2021-11-27 14:53:40
C++ / C#
syxme, 2021-11-27 14:53:40

C++ interfaces like in java, declaration inside a function how to make it beautiful?

There is a virtual class c++

class IEvent {
  public:
    virtual void onClick(int index) = 0;
};


At the moment I create it and install it like this:
struct audioAdapterArtistEvents : AdapterAudio::IEvent {
    PlaylistGUIManager &base;

    explicit audioAdapterArtistEvents(PlaylistGUIManager &base) : base(base) {};

    void onClick(int index) override {
      base.mediaServiceBase->getPlaySession()->BasePlayAudio(base.mAudioAdapter.visibleList,index);
    }
  };

  mAudioAdapter.onClickArtist(new audioAdapterArtistEvents(*this));


But it doesn’t look very nice, I would like it to be like in java, for example
mAudioAdapter.onClickArtist(new AdapterAudio.IEvent() {
     @Override
     public void onClick(int index) {
                //....
    }
});


Is it possible somehow in c++ to declare a class inside a function parameter like in java?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-27
@syxme

Is it possible somehow in c++ to declare a class inside a function parameter like in java?

No.
But for stuff like this you can use lambdas :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question