We currently have a hierarchy of Inset classes so:
class Inset {};
class InsetButton : public Inset {};
class InsetCommand: public InsetButton {};
class InsetCitation : public InsetCommand {};
I'd like to split InsetButton into InsetEditableButton and
InsetNonEditableButton() and to use virtual base classes:
class Inset {};
class InsetEditableButton : virtual public Inset {};
class InsetNonEditableButton : virtual public Inset {};
class InsetCommand: virtual public Inset {};
class InsetCitation : public InsetCommand, public InsetEditableButton {};
Am I allowed to do this? (The "virtual" costs us nothing as far as I can see,
here at least, because Inset is a pure abstract class.)
Angus
PS Here's the working example code:
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
class Inset {
public:
virtual void draw() const = 0;
virtual int latex() const = 0;
};
class InsetEditableButton : virtual public Inset {
public:
void draw() const
{
cout << "InsetEditableButton::draw()" << endl;
}
};
class InsetNonEditableButton : virtual public Inset {
public:
void draw() const
{
cout << "InsetNonEditableButton::draw()" << endl;
}
};
class InsetCommand: virtual public Inset {
public:
virtual int latex() const
{
cout << "InsetCommand::latex()" << endl;
return 0;
}
};
class InsetCitation : public InsetCommand, public InsetEditableButton {
public:
virtual int latex() const
{
cout << "InsetCitation::latex()" << endl;
return 0;
}
};
int main() {
InsetCitation example;
example.draw();
example.latex();
return 0;
}