What is a pure virtual function? (2)

So to generate the index to an array, instead of doing:

for(int ix=0;ix<spectrum_x;ix++) {
    if(nch == 1) { /* IC7410 */
        ixx = ix;
    } else if(nch == 2) { /* Soft66LC4 */
        ixx = (2*nfft - (spectrum_x/2) + ix) % nfft;
    }
    // other stuff
}

we do:

for(int ix=0;ix<spectrum_x;ix++) {
    ixx = s->get_index(ix, nfft, spectrum_x);
    // other stuff
}
class Sound : public AlsaParams { /* abstract base class */
public:
    virtual int get_index(int, int, int) const = 0;
    // other stuff
};
class SoundIC7410: public Sound { /* IC7410 */
public:
    int get_index(int i, int, int) const override { return i; }
    // other stuff
};
class SoundSoft66: public Sound { /* Soft66LC4 */
public:
    int get_index (int i, int j, int k) const override { return (2*j-(k/2)+i)%j; }
    // other stuff
};

I do not know which style looks better and is more maintainable.

IC-7410 Rig Control Program (C++ version)_032

The window is now scrollable again.

//============================================================================
// Name        : Rig008.cpp
//============================================================================

#include "SoundIC7410.h"
#include "SoundSoft66.h"
#include "MyDrawingArea.h"
#include "MyWindow.h"
#include <gtkmm.h>
#include <vector>
#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
	if (argc != 3) {
		cout << "Usage example: " << argv[0] << " hw:2,0 hw:1,0 " << endl;
		return 1;
	}

	vector <Sound*> soundlist;
	soundlist.push_back( new SoundIC7410{argv[1]} );
	soundlist.push_back( new SoundSoft66{argv[2]} );

	argc = 1;			/* just for the next line */
	Glib::RefPtr < Gtk::Application > app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
	MyWindow win(soundlist);
	return app->run(win);
}
/* MyWindow.h */

#ifndef MYWINDOW_H_
#define MYWINDOW_H_

#include "Sound.h"
#include <gtkmm.h>
#include <vector>
using namespace std;

class MyWindow : public Gtk::Dialog {
public:
	MyWindow(vector <Sound*> &slist);
	virtual ~MyWindow();
private:
  Gtk::ScrolledWindow myscrolledwindow;
  Gtk::VBox           myvbox;
};

#endif /* MYWINDOW_H_ */
/* MyWindow.cpp */

#include "MyWindow.h"
#include "MyDrawingArea.h"

MyWindow::MyWindow(vector <Sound*> &slist) {
	set_title("IC-7410 Rig Control Program (C++ version)");
	set_size_request(1800, 900);
	myscrolledwindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
	get_content_area()->pack_start(myscrolledwindow);
	for(auto s : slist) {
		myvbox.pack_start( *(new MyDrawingArea{s}), FALSE, FALSE, 0);
	}
	myscrolledwindow.add(myvbox);
	add(myscrolledwindow);
	show_all();
}

MyWindow::~MyWindow() {
}

https://github.com/jh1ood/sprigmm/tree/develop