lundi 22 avril 2019

How to implement logic gates in in C++

I am a self taught in C++ and I have been developing a control software in this programming language. My design contains among others also a C++ class which models AND gate with two inputs. At some point I have found that it would be fine to have AND gates with more than two inputs (eight inputs in maximum). My question is how to achieve this in the best way in C++?

I have been thinking about class templates. Is it good idea or is it better to use composition i.e. AND_03 consists of two AND_02 gates?

class AND_02 : public Logic_FB{

private:

public:
void AND_02(uint32_t result, uint32_t input_01, uint32_t input_02);
void update(void);

} 

where

class Logic_FB{
    virtual void update(void) = 0;
}

is unified interface for other logic elements like OR gate, RS flip-flop and so on.

Aucun commentaire:

Enregistrer un commentaire