C++ C++;使用x64时异步返回值不同
下面的代码在VC2013中使用Debug\Win32和Debug\x64设置进行编译,但是当我使用Debug\x64时,我得到以下智能感知错误:C++ C++;使用x64时异步返回值不同,c++,visual-studio,visual-studio-2013,64-bit,stdasync,C++,Visual Studio,Visual Studio 2013,64 Bit,Stdasync,下面的代码在VC2013中使用Debug\Win32和Debug\x64设置进行编译,但是当我使用Debug\x64时,我得到以下智能感知错误: IntelliSense: no operator "=" matches these operands operand types are: std::future<bar<int>> = std::future<bar<int> (&)(bar<int> v)>
IntelliSense: no operator "=" matches these operands
operand types are: std::future<bar<int>> = std::future<bar<int> (&)(bar<int> v)>
IntelliSense:没有与这些操作数匹配的运算符“=”
操作数类型为:std::future=std::future
此错误与Header.cpp中的此函数有关:
bar<int> test::call(bar<int> v)
{
std::future<bar<int>> ret;
ret = std::async(std::launch::async, &test::exec, this, v);
return ret.get();
}
bar测试::调用(bar v)
{
标准:未来可再生能源;
ret=std::async(std::launch::async,&test::exec,this,v);
返回ret.get();
}
为什么std::async在使用x64时返回不同的结果
返回值win32:
std::future<bar<int>>
std::未来
返回值x64:
std::future<bar<int> (&)(bar<int>
std::futurePost真正的编译器错误或警告,而不是Intellisense消息
您可能必须使用std::move
。
#pragma once
#include <future>
#include <iostream>
using namespace std;
template <typename T>
class bar
{
public:
bar()
{
state = 9;
}
void dec(){ state--; }
T show()
{
return state;
}
private:
T state;
};
class test{
public:
test(int a);
public:
bar<int> call(bar<int> v);
private:
bar<int> exec(bar<int> v);
private:
int value;
};
#include "Header.h"
using namespace std;
test::test(int a)
{
value = a;
}
bar<int> test::call(bar<int> v)
{
std::future<bar<int>> ret;
ret = std::async(std::launch::async, &test::exec, this, v);
return ret.get();
}
bar<int> test::exec(bar<int> v)
{
v.dec();
v.dec();
return v;
}
#include <future>
#include <iostream>
#include "Header.h"
using namespace std;
int main()
{
test object(4);
bar<int> foo;
bar<int> other = object.call(foo);
std::cout << other.show();
getchar();
}
IntelliSense: no operator "=" matches these operands
operand types are: std::future<bar<int>> = std::future<bar<int> (&)(bar<int> v)>