gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:07:54 24 4
gpt4 key购买 nike

我的代码看起来像下面这样:

#include <array>

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

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

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

我看过tuple_size and an inhereted class from tuple?但由于那只谈论 std::tuple 我认为它不能应用。知道为什么这不起作用吗?是否有一种简单的方法让它起作用?

最佳答案

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

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

关于c++ - 在从 std::array 派生的类上使用 std::tuple_size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11177783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com