All submissions

Friend Function Access

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

class Register8 {
private:
    uint8_t value;
public:
    void setValue(uint8_t v) { 
        value = v;
    }
    friend void printRegister(const Register8& r);
        // your code here: declare a friend function printRegister(const Register8& r)

};

void printRegister(const Register8& r){
    cout<<"Register value = "<<(int)r.value<<endl;
}

// your code here: implement printRegister that prints "Register value = <value>"

int main() {
    Register8 r;
    r.setValue(170);
    printRegister(r);
    return 0;
}
Loading...

Input

Expected Output

Register value = 170