GPIO Pin Operator Overload

#include <iostream>
#include <cstdint>
using namespace std;

// Define enum class Level
enum class Level : uint8_t{
    LOW=0,
    HIGH=1
};
// Define class GpioPin with operator= and operator int()
class GpioPin{
    private:
        Level level =Level::LOW;
    public:
    GpioPin(Level level_val){
        level = level_val;
    }
    void operator=(Level level_val){
        level = level_val;
    }
    operator int() const{
        return static_cast<int>(level);
    }
};

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