[Solved] Passing a member function to Noesis::SetLogHandler()
Hey y'all,
I prefer to avoid lambda functions unless necessary, given their increased power/complexity compared to 'standard' functions. I've unsuccessfully attempted to pass a member function to the Noesis::SetLogHandler() function. Attempted approaches:
std::bind()
No bueno, as std::bind() returns an unspecified type https://stackoverflow.com/questions/631 ... d-function
std::function
Setting aside my concern for how long 'f' exists beyond the scope it's declared in, and if that'd cause issues, I still receive this error with this approach:
E0413 no suitable conversion function from "std::function<void (const char *, uint32_t, uint32_t, const char *, const char *)>" to "Noesis::LogHandler" exists
Which... Well... Alright, they're supposedly the same type, but I guess a typedef != std::function?
Anonymous namespace function
My current best solution is to simply implement a function in an anonymous namespace and use it:
This avoids the lambda function, but doesn't allow me to use a member function.
I'm open to any ideas/suggestions!
Thanks in advance,
Gazoo
I prefer to avoid lambda functions unless necessary, given their increased power/complexity compared to 'standard' functions. I've unsuccessfully attempted to pass a member function to the Noesis::SetLogHandler() function. Attempted approaches:
std::bind()
Code: Select all
Noesis::SetLogHandler( std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
std::function
Code: Select all
std::function<void( const char*, uint32_t, uint32_t, const char*, const char* )> f = std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
Noesis::SetLogHandler( f );
E0413 no suitable conversion function from "std::function<void (const char *, uint32_t, uint32_t, const char *, const char *)>" to "Noesis::LogHandler" exists
Which... Well... Alright, they're supposedly the same type, but I guess a typedef != std::function?
Anonymous namespace function
My current best solution is to simply implement a function in an anonymous namespace and use it:
Code: Select all
namespace {
void MyLogger( const char*, uint32_t, uint32_t level, const char*, const char* msg )
{
}
}
I'm open to any ideas/suggestions!
Thanks in advance,
Gazoo
Last edited by Gazoo on 18 Oct 2022, 11:51, edited 1 time in total.
Re: Passing a member function to Noesis::SetLogHandler()
Unfortunately this is not possible with the current API. Please report if this is a blocking feature for your development.
Re: Passing a member function to Noesis::SetLogHandler()
Not a blocker as such. More of a minor annoyance. Really appreciate confirming that it isn't currently possible. The anonymous namespace function is preferable to me, compared to the lambda function.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 15 guests