问题
The following Code compiles using both Debug\Win32 and Debug \ x64 settings in VC2013, but when I use Debug \ x64 i get the following IntelliSense Error:
IntelliSense: no operator "=" matches these operands
operand types are: std::future<bar<int>> = std::future<bar<int> (&)(bar<int> v)>
The Error refers to this function in 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();
}
Why does std::async return something diffrent when using x64?
return value win32:
std::future<bar<int>>
return value x64:
std::future<bar<int> (&)(bar<int>
How can i fix this for x64?
My Code:
Header.h
#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;
};
Header.cpp
#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;
}
Source.cpp
#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();
}
Edit: I do not want to use auto, because auto would not work in other scenarios (for example creating a vector of futures and then pushing back futures)
This Error is NOT a compiler error, the code compiles and executes flawlesly ==> i can't post the compiler error because there is no compiler error. I just want to get rid of the VC IntelliSense Error
Using std::move() does not solve the problem, i still get an IntelliSense Error: (The Code compiles and executes perfectly with and without the use of std::move)
IntelliSense: no operator "=" matches these operands
operand types are: std::future<bar<int>> = std::future<bar<int> (&)(bar<int> v)>
来源:https://stackoverflow.com/questions/27652485/c-async-return-value-different-when-using-x64