Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ lambda callbacks, how to initialize with NULL pointer ?

C++ lambda callbacks, how to initialize with NULL pointer ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpvisual-studiolinq
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 8534035
    wrote on last edited by
    #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>]

    Richard Andrew x64R 1 Reply Last reply
    0
    • M Member 8534035

      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>]

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Here's a stab in the dark: Instead of initializing to NULL, try setting it to nullptr .

      The difficult we do right away... ...the impossible takes slightly longer.

      M 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Here's a stab in the dark: Instead of initializing to NULL, try setting it to nullptr .

        The difficult we do right away... ...the impossible takes slightly longer.

        M Offline
        M Offline
        Member 8534035
        wrote on last edited by
        #3

        oh....you are right! with nullptr it works!!! never, never used it before! Many Thanks Richard

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups