[ANSWERED] Overloading the << operator for conducting checks before output to STDOUT
I am trying to make a Button Class to print certain boxes on a text based console window in Windows that may be interfaced with by the user by actions like hovering on it, clicking it, etc. I also made a Console class to handle console properties like Size, Foreground and Background Text Colors, Cursor Positions for Printing, etc. Now, I want to prevent the << operator to print on the button or any such element. So, I created a vector of 4 points to store the area of the Button and tried to overload << to check before output that the current cursor position does not lie on the buttons : template <typename T> std::ostream& operator<<(std::ostream& os, T obj) { // SMALL_RECT is a struct of 4 points. Console::Reserved() returns the vector with all // the saved area points. std::vector<SMALL_RECT> Res = Console::Reserved(); CONSOLE_SCREEN_BUFFER_INFO cb; GetConsoleScreenBufferInfo(Console::Out(),&cb); COORD c = cb.dwCursorPosition; for(SMALL_RECT s : Res) { if((c.X>=s.Left||c.X<=s.Right)||(c.Y>=s.Top||c.Y<=s.Right)) throw std::logic_error(">> Console : Space reserved for UI Element!"); } os<<obj; return os; } However, the overload failed, as when I tried printing a single character somewhere else on the console, I got a lot of errors, like the following : error: ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const unsigned char') error: ambiguous overload for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}') Why do these errors occur? Is there a solution? If not, is there another way I can achieve a similar result?