存储指向整数向量向量元素的指针向量

Storing a vector of pointers to elements of a vector of vector of ints

如果我说 std::vector<std::vector<int>> test_vofv 存储整数向量的向量。

我现在想将指向各种元素的指针(我指的是外部向量,即 test_vofv[0]test_vofv[1])存储在一个单独的向量中,即 std::vector<pointer> vector_of_pointers

"pointer" 类型实际上应该是什么?将其设置为 std::vector<std::vector<int>>* 是不正确的。

将其设置为 std::vector<std::vector<int>>* 是不正确的,因为这会声明一个指向整数向量向量的指针。指针类型从右到左读取。

你想要的是指针向量。这意味着像 std::vector<something*> 这样的声明,其中有你想要指向的东西。在您的例子中,指向整数向量的指针向量是 std::vector<std::vector<int>*> vector_of_pointers。您首先读取外部矢量,然后读取内部的指针,然后是指针指向的任何内容。