c++ - C++ `using {var}` 不是 {child class} 的成员 - 在 MSVC 或 Clang 中使用`std::deque` 时
问题描述
下面的代码error C2039: 'value_type': is not a member of 'Child_Container'
在第 7 行给出了错误。这发生在 MSVC 和 Clang 中,但不会发生在 GCC 中。从而在使用时std::deque
,而不是std::set
,std::vector
。有谁知道为什么?谢谢!
#include <deque>
template<typename T_Container>
struct _View
{
using NOPE = typename T_Container::value_type;
};
template<typename T_type, typename T_Self>
struct Base_Container
{
using value_type = T_type;
std::deque<_View<T_Self>> _views;
};
struct Child_Container : public Base_Container<double, Child_Container>
{
// using value_type = double; // Even with this line.
using base = Base_Container<value_type, Child_Container>;
};
int main()
{
return 0;
}
解决方案
这里的变量只是实例化时是否std::deque
要求其元素类型完整。(当然,当某些成员函数被实例化时,它必须是完整的,但这是分开的。)如果是这样,你最终需要value_type
在它被声明之前,这会产生观察到的错误。C++17 要求std::vector
支持不完整类型,但没有提及std::deque
,这就是每个标准库不同的原因。
推荐阅读
- wordpress - Woocommerce 禁用设置向导
- r - 如何将特定数据从一个数据帧添加到另一个更大的数据帧?
- html - 如何使用不是背景的图像创建 5x4 的纵横比?
- javascript - 如何找到嵌套在元素内的下一个选择下拉菜单?
- go - 使用此代码,您如何知道是否会使用 sha256 或 sha512?
- python - 已安装 Python 2.7 和 Python 3.7。如何在 Python 2.7 中使用 MadGraph?
- arrays - Swift 数组中的负索引
- selenium-webdriver - 如何在 selenium webDriver 中获取新打开的选项卡的驱动程序实例
- database - 非关键属性的唯一性是否违反 3NF?
- angular - 如何在Angular 7中将数据从孩子传递给父母