【发布时间】:2017-04-11 03:57:57
【问题描述】:
以下类无法编译:
template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class MyContainer
{
public:
std::vector<Key, Allocator> data;
std::vector<std::pair<std::size_t, decltype(data)::size_type>> order;
};
我收到以下编译器错误:
错误:“模板结构 std::pair”的模板参数列表中的参数 2 的类型/值不匹配
为什么编译失败,而下面的代码可以正常工作?
template<class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key>>
class MyContainer
{
public:
std::vector<Key, Allocator> data;
std::vector<std::pair<std::size_t, std::size_t>> order;
};
【问题讨论】:
标签: c++ c++11 templates vector decltype