Tôi đã cố gắng lưu trữ một đối tượng foo
vào một std::reference_wrapper
, nhưng tôi kết thúc với lỗi trình biên dịch mà tôi không hiểu.Lưu trữ tài liệu tham khảo trong một bản đồ
#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);
}
Các lỗi biên dịch là khá dài, nhưng nó nắm này:
error: no matching function for call to ‘std::reference_wrapper<foo>::reference_wrapper()’
chính xác tôi làm gì sai?
std :: reference_wrapper không có constructor mặc định –