0

I´m working with the windows Kinect in c++. I am trying to check if the right Hand went from the right to the left shoulder, like a wiping move. I´m trying to work with std::async because I need the returning value of the method. I already googled the error i got and have no Idea whats the matter.

My 2 Methods which I use:

   bool NuiSkeletonStream::timeNext(clock_t start)
{
    clock_t end, diff;

    end = clock();
    diff = end - start;

    while(diff <= 1500)
    {
        if(diff >= 1500)
        {
            if(i_rhx == i_lsx && i_rhy == i_lsy)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            diff = end - start;
            end = clock();
        }
    }
}

bool NuiSkeletonStream::runNext()
{
    clock_t start;

//  std::thread compare(timeNext(start),std::move(xNext));
    for (int i = 0; i < NUI_SKELETON_COUNT; i++)
    {
        if (m_skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED)
        {
            i_rhx = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].x*5+5;
            i_rhy = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT].y*5+5;
            //i_rhz = (m_skeletonFrame.SkeletonData[i].SkeletonPositions[11].z*10)-10;
            i_rsx = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_RIGHT].x*5+5;
            i_rsy = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_RIGHT].y*5+5;
            i_lsx = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_LEFT].x*5+5;
            i_lsy = m_skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_LEFT].y*5+5;

            if(i_rhx == i_rsx && i_rhy == i_rsy)
            {
                start = clock();
                auto f1 = std::async(timeNext(start));

            }
        }
    }

I have the following error:

Error   24  error C2440: 'return' : cannot convert from 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type' to '_Ret'
Arya
  • 371
  • 2
  • 17
Spirit
  • 43
  • 1
  • 7
  • Bonus: your usage of std::async is not really async. Basically you need to catch the returned future and keep it alive. See the example at http://en.cppreference.com/w/cpp/thread/async – sbabbi Sep 26 '13 at 11:21

1 Answers1

2

With the expression

std::async(timeNext(start));

you actually call timeNext yourself, and passing its return value (a bool) to std::async.

If you see e.g. this reference you will see that the std::async function takes the function as first argument, and then the arguments to the function.

So you should do

std::async(&NuiSkeletonStream::timeNext, this, start);
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • I edited the Code but if I write std::async(timeNext, start); the argument list doesnt match and i get a new error. 31 IntelliSense: no instance of overloaded function "std::async" matches the argument list argument types are: (bool (clock_t start), clock_t) – Spirit Sep 26 '13 at 09:36
  • @Spirit Is it only an *Intellisense* error, or a proper *compilation* error? – Some programmer dude Sep 26 '13 at 09:44
  • I have 11 more REAL errors so I guess it´s not only the intellisense. The Errors say that there are too less or too many arguments for this Method. Then there is this error: `Error 10 error C3867: 'NuiSkeletonStream::timeNext': function call missing argument list; use '&NuiSkeletonStream::timeNext' to create a pointer to member` But if I add the `&` I just get another Compiling error called `Error 10 error C2276: '&' : illegal operation on bound member function expression` – Spirit Sep 26 '13 at 10:17
  • @Spirit Updated my answer and how to call `std::async`. – Some programmer dude Sep 26 '13 at 10:27
  • Okay it worked. I just dont understand why. Can you maybe explain to me why I need the `this`? – Spirit Sep 26 '13 at 10:38
  • @Spirit All class member functions has a hidden first argument, that is the `this` pointer. Normally when you call a member function, the compiler passes this hidden argument for you, but when passing member functions to e.g. `std::async` or the `std::thread` constructor it can't be done. So you have to explicitly pass the object instance the member function should be called on as the first argument. – Some programmer dude Sep 26 '13 at 10:42