81. Non-Copyable UART Handle

You are implementing a class that represents a UART hardware handle.

Each instance controls one physical UART peripheral, so it must not be copied.

Copying this object would incorrectly imply:

  • Two objects controlling the same UART
  • Conflicting writes
  • Multiple initializations
  • Incorrect baud configuration
  • Hardware misuse in firmware

To prevent this, copying must be explicitly disabled.

You must implement:

  • A constructor initializing the UART with a baud rate
  • A sendByte() function that prints the transmitted byte
  • A deleted copy constructor
  • A deleted copy assignment operator

Your class must be non-copyable.

Demonstration requirement:

Inside main(), an attempted copy is included:

// UARTHardware copy = uart;   // This line should NOT compile after your implementation 

This line is intentionally commented out.

If the user un-comments it, the code must fail to compile, proving copying is forbidden.

Program Flow:

  1. Read a baud rate
  2. Read a byte to send
  3. Create a UART object
  4. Attempted copy line is present (commented)
  5. Send the byte

 

Example Input:

9600 65 

Example Output:

TX: 65 

 

Constraints:

  • Baud rate is a positive integer
  • Byte value is 0–255
  • Copying must be disallowed via deletion
  • Output must match exactly

 

 

 

Loading...

Input

9600 65

Expected Output

TX: 65