Non-Copyable UART Handle

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

class UARTHardware {
private:
    int baud;

public:
    // Implement constructor to store baud rate
    UARTHardware(int b):baud(b){}

    // Delete copy constructor
    UARTHardware(const UARTHardware& uh) = delete;

    // Delete copy assignment operator
    UARTHardware& operator=(const UARTHardware& uh) = delete;

    void sendByte(uint8_t value) const {
        cout << "TX: " << (int)value;
    }
};

int main() {
    int baudRate;
    cin >> baudRate;

    int temp;
    cin >> temp;
    uint8_t byteToSend = (uint8_t)temp;

    UARTHardware uart(baudRate);

    // Demonstration (must not compile if uncommented)
    // UARTHardware copy = uart;

    uart.sendByte(byteToSend);
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

9600 65

Expected Output

TX: 65