in my code, I want to implement a function that prints any data type to console.
the function always receives a string
as the first argument and a data which can vary each time as the second argument.
Mutex_Loggers.h
namespace Loggers
{
std::mutex m_mutex;
template<typename T>
void sharedLog(const std::string& message, T data)
{
std::lock_guard<std::mutex> locker(m_mutex);
std::cout << message << data << std::endl;
}
}
and one of the files which calls it like e.g. main.cpp
#include "Mutex_Loggers.h"
/*other stuff*/
Loggers::sharedLog("IN THREAD: ", std::this_thread::get_id());
Loggers::sharedLog("IN APP CREATION ", nullptr);
Loggers::sharedLog("IN create_CtrApp_and_register ", {1,2,3});
at compile time I get these errors:
C2593 operator
<<
is ambiguousC2679 binary
<<
no operator found which takes a right-hand operand of typeT
(or there is no acceptable conversion)
How can I have function that prints any type of data