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'
有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top