【发布时间】:2015-03-31 08:10:00
【问题描述】:
我尝试将 foo 对象存储到 std::reference_wrapper 中,但最终出现我不理解的编译器错误。
#include <functional>
#include <map>
struct foo
{
};
int main()
{
std::map< int, std::reference_wrapper< foo > > my_map;
foo a;
my_map[ 0 ] = std::ref( a );
}
编译器错误很长,但归结为:
error: no matching function for call to ‘std::reference_wrapper<foo>::reference_wrapper()’
我到底做错了什么?
【问题讨论】:
-
std::reference_wrapper 没有默认构造函数