Register8 Equality Operator

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

class Register8 {
private:
    uint8_t value;
public:
    Register8(uint8_t v) : value(v) {}

    // Define operator== to compare two Register8 objects
    friend bool operator==(Register8& r1, Register8& r2){
        return r1.value==r2.value;
    }

    uint8_t getValue() const {
        return value;
    }
};

int main() {
    int a, b;
    cin >> a >> b;

    Register8 r1(static_cast<uint8_t>(a));
    Register8 r2(static_cast<uint8_t>(b));

    if (r1 == r2)
        cout << "Equal";
    else
        cout << "Not Equal";

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

10 10

Expected Output

Equal