智能指针二维数组作为参数

Smart pointer 2D array as a parameter

我试图通过发送一个通过智能指针创建的二维数组作为参数来return函数中的第三大数字,但问题是,我不知道该怎么做。我一直在互联网上搜索可能的解决方案,但似乎找不到,这就是我所做的,

int thirdhigh(int array[4][5])
{}

int main()
{
    std::shared_ptr<std::shared_ptr<int[]>[]>array(new std::shared_ptr<int[]>[4]);//creates an array of pointers

    //creates an array of size 5 and sends it addressess to the previous created array of pointers
    for (int rows{ 0 }; rows < 4; ++rows) {
        array[rows] = std::shared_ptr<int[]>(new int[5]);
    }

    //assigns random values to the 2D array created from 1-100
    for (int r{ 0 }; r < 4; ++r) {
        for (int c{ 0 }; c < 5; ++c) {
            array[r][c] = ((rand() % 100) + 1);
        }
    }

    //Shows the values assigned to the 2D array
    for (int r{ 0 }; r < 4; ++r) {
        for (int c{ 0 }; c < 5; ++c) {
            std::cout << array[r][c] << "\t";
        }
        std::cout << std::endl;
    }
    //Returns the third highest number
    thirdhigh(array[4][5]);
}

另外,我只需要在尝试学习智能指针时使用它。任何的意见都将会有帮助。谢谢!

std::shared_ptr<std::shared_ptr<int[]>[]> 是你要传递给函数的东西的类型,而不是 int[4][5]。此外,由于 std::shared_ptr<> 不知道在它指向的内存位置有多少个连续的东西,因此您还必须将维度传递给函数。