C++ lambda callbacks, how to initialize with NULL pointer ?
-
Hi all, I need callback functions between different classes. I had already a solution based on stl, which was compilable with VS2010. Unfortunately I was not able to find a way to compile it with VS2015. I got weird error messages. Now I found a solution with lamda C++11 lambda function pointers. Actually it works, but I have one open issue. For having a save source code, I want to initialize the function pointer with NULL. But compiler is producing weird error messages again! My Code:
typedef std::function _tcedit_cb_;
class MyClass
{
public:
MyClass ()
{
m_cbGetItemData = NULL; // <--- compile error because of the NULL pointer
}
_tcedit_cb_ m_cbGetItemData;...
}How I can initialize the function callback pointer? I need to initialize in order to avoid running into illegal code! e.g. I tried to cast ... = (_tcedit_cb_) NULL; error messages:
c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : error C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : With the following template arguments :
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Callable=_Decayed &'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Types={int, int, ATL::CStringT>> }'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\functional(210) : note : see reference to function template instantiation '_Rx std::_Invoke_ret<_Rx,_Callable&,_Ty,_Ty,ATL::CStringT>>>(std::_Forced<_Rx,false>,_Callable &,_Ty &&,_Ty &&,ATL::CStringT>> &&)' being compiled
1> with
1>[
1> _Rx = bool,
1> _Callable = _Decayed,
1> _Ty = int
1>] -
Hi all, I need callback functions between different classes. I had already a solution based on stl, which was compilable with VS2010. Unfortunately I was not able to find a way to compile it with VS2015. I got weird error messages. Now I found a solution with lamda C++11 lambda function pointers. Actually it works, but I have one open issue. For having a save source code, I want to initialize the function pointer with NULL. But compiler is producing weird error messages again! My Code:
typedef std::function _tcedit_cb_;
class MyClass
{
public:
MyClass ()
{
m_cbGetItemData = NULL; // <--- compile error because of the NULL pointer
}
_tcedit_cb_ m_cbGetItemData;...
}How I can initialize the function callback pointer? I need to initialize in order to avoid running into illegal code! e.g. I tried to cast ... = (_tcedit_cb_) NULL; error messages:
c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : error C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : With the following template arguments :
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Callable=_Decayed &'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Types={int, int, ATL::CStringT>> }'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\functional(210) : note : see reference to function template instantiation '_Rx std::_Invoke_ret<_Rx,_Callable&,_Ty,_Ty,ATL::CStringT>>>(std::_Forced<_Rx,false>,_Callable &,_Ty &&,_Ty &&,ATL::CStringT>> &&)' being compiled
1> with
1>[
1> _Rx = bool,
1> _Callable = _Decayed,
1> _Ty = int
1>]Here's a stab in the dark: Instead of initializing to
NULL
, try setting it tonullptr
.The difficult we do right away... ...the impossible takes slightly longer.
-
Here's a stab in the dark: Instead of initializing to
NULL
, try setting it tonullptr
.The difficult we do right away... ...the impossible takes slightly longer.
oh....you are right! with
nullptr
it works!!! never, never used it before! Many Thanks Richard