Say I have the following abstract base class:
class DLAContainer {
public:
DLAContainer() { std::random_device rd; mt_eng = std::mt19937(rd()); }
virtual void generate(std::size_t _n) = 0;
protected:
std::mt19937 mt_eng;
virtual void spawn_particle(int& _x, int& _y,
std::uniform_real_distribution<>& _dist) = 0;
virtual void spawn_particle(int& _x, int& _y, int& _z,
std::uniform_real_distribution<>& _dist) = 0;
};
and two classes that inherit from DLAContainer:
class DLA_2d : public DLAContainer {
public:
DLA_2d() : DLAContainer() {
void generate(std::size_t _n) {
private:;
std::queue<std::pair<int,int>> batch_queue;
void spawn_particle(int& _x, int& _y,
std::uniform_real_distribution<>& _dist) {
void spawn_particle(int& _x, int& _y, int& _z,
std::uniform_real_distribution<>& _dist) {
};
and
class DLA_3d : public DLAContainer {
public:
DLA_3d() : DLAContainer() {
void generate(std::size_t _n) {
private:;
std::queue<std::tuple<int,int,int>> batch_queue;
void spawn_particle(int& _x, int& _y,
std::uniform_real_distribution<>& _dist) {
void spawn_particle(int& _x, int& _y, int& _z,
std::uniform_real_distribution<>& _dist) {
};
As you can see, there are two overloads spawn_particle- one for the 2D lattice and the other for 3D, however both are pure virtualfunctions and therefore must be redefined / implemented both in DLA_2dand DLA_3dwhere the 3D method will do nothing in DLA_2dand vice versa for DLA_3d.
Of course, this works, and everything works fine, but I can't help but feel that the design is a bit awkward when you have to apply irrelevant methods in each class.
, , (.. ISpawnParticle_2d ISpawnParticle_3d) ? , ?
: , DLAContainer ( ). ( DLA_2d, DLA_3d), , spawn_particle - DLAContainer .