GPIO Pin Operator Overload

#include <iostream>
using namespace std;

enum class Level{LOW=0, HIGH=1};

class GpioPin{
    
    private:
        Level pin_state;

    public:
        explicit GpioPin(Level state): pin_state(state){}

        GpioPin& operator=(Level next_state){
            this->pin_state = next_state;
            return *this;
        }

        operator int(){
            return static_cast<int>(pin_state);
        }
};

int main() {
    int init, next;
    cin >> init >> next;

    GpioPin pin(static_cast<Level>(init));

    pin = static_cast<Level>(next);

    cout << pin;

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

0 1

Expected Output

1