gpt4 book ai didi

c++ - typedef Vec Vec2i;这个定义是什么意思?

转载 作者:行者123 更新时间:2023-11-28 02:43:30 24 4
gpt4 key购买 nike

我在大约 5 年后回到了 C++。我赶紧复习一下。但是有一个定义我不知道。

std::vector 是一个类模板。

typedef Vec<int, 2> Vec2i;
typedef Vec<int, 3> Vec3i;
typedef Vec<int, 4> Vec4i;
typedef Vec<int, 6> Vec6i;
typedef Vec<int, 8> Vec8i;

我不知道数字是什么意思?是字节的意思吗?

它来自core.hpp

/*!
A short numerical vector.

This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements)
on which you can perform basic arithmetical operations, access individual elements using [] operator etc.
The vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc.,
which elements are dynamically allocated in the heap.

The template takes 2 parameters:
-# _Tp element type
-# cn the number of elements

In addition to the universal notation like Vec<float, 3>, you can use shorter aliases
for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>.
*/
template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>

最佳答案

据推测,Vec 是一个表示 N 维数学 vector 的类模板,类似于:

template <typename T, int N> class Vec { /* ... */ };

数字指定 vector 中元素的数量,即具有整数分量的 2D vector 、具有整数分量的 3D vector 等。

但是没有代码就不可能说。

关于c++ - typedef Vec<int, 2> Vec2i;这个定义是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145435/

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