-
Notifications
You must be signed in to change notification settings - Fork 0
ToString
Maxime ROUFFET edited this page Mar 21, 2023
·
3 revisions
During logging, the SA::ToString
(and SA::ToWString
) function is automatically called to log any variable.
For custom class types, by default, a binary conversion string will be logged:
namespace MyNamespace
{
class MyClass
{
public:
int i = 0;
};
}
// main.cpp
MyNamespace::MyClass m1{ 72 };
SA_LOG(m1);
[18:43:59] {Normal - Default} main.cpp:54 - int main()
Msg: <00-00-00-48>
By adding the SA::ToString
(or SA::ToWString
) specialization for a class type, the new implementation will be called instead.
The SA::ToString
specialization must be included before calling the SA_LOG macro.
namespace SA
{
// Must be defined in SA::
template <>
std::string ToString(const MyNamespace::MyClass& _m)
{
return "MyNamespace::MyClass: " + std::to_string(_m.i);
}
}
[18:42:12] {Normal - Default} main.cpp:55 - int main()
Msg: MyNamespace::MyClass: 72
See main.cpp for a complete example.