繁体   English   中英

在从std :: array派生的类上使用std :: tuple_size

[英]Using std::tuple_size on classes derived from std::array

我的代码有点像以下代码:

#include <array>

class DoubleArray: std::array<double, 16> {
public:
    void clear() {
        fill(0.0);
    }
};

现在,我想使用std::array的大小作为编译时间常数。 如果DoubleArray只是std::arraytypedef ,我可以使用std::tuple_size<DoubleArray>::value但使用继承却得到以下编译器错误:

error: incomplete type ‘std::tuple_size<DoubleArray>’ used in nested name specifier

我看过tuple_size和inpleed类从tuple吗? 但是由于那只谈论std :: tuple,所以我认为它不能被应用。 有什么想法为什么不起作用以及是否有简单的方法使其起作用?

只需调用size() -对于数组,它就是一个constexpr

参见此处: http ://en.cppreference.com/w/cpp/container/array/size或查看§23.3.2.1.3,其中定义为constexpr size_type size() noexcept;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM