How can I add an element via emplace(pos, value) if I have a two-dimensional vector?

46 views Asked by At

There is a code like this:

using d2dArray = vector<vector<double>>; // Псевдоним

d2dArray calcNextArray(d2dArray array)
{
    d2dArray nextArray;
    int nextArrSize = array.size() - 1;
    d2dArray detArray = { {0, 0}, {0, 0} };

    for (int i = 0; i < nextArrSize; i++) // Идём по столбцу
    {
        for (int j = 0; j < nextArrSize; j++) // Идём по строке
        {
            detArray[0][0] = array[0 + i][0 + j];
            detArray[0][1] = array[0 + i][1 + j];
            detArray[1][0] = array[1 + i][0 + j];
            detArray[1][1] = array[1 + i][1 + j];

            nextArray.emplace(*pos*, calcDeterminant(detArray)); // The problem is here.

            //calcDeterminant(detArray) - returns double

        }
    }

    return nextArray;
}

The code should calculate the determinants and write them into a new vector, but since I just started learning vectors in C++, I don't understand how to work with multidimensional vectors. And information so specific is difficult to find, unless you read all the documentation.

The problem is solved!

d2dArray calcNextArray(d2dArray array)
{
    int nextArrSize = array.size() - 1;
    d2dArray nextArray(nextArrSize, d1dArray(nextArrSize));
    d2dArray detArray(2, d1dArray(2));

    for (int i = 0; i < nextArrSize; i++) // Идём по столбцу
    {
        for (int j = 0; j < nextArrSize; j++) // Идём по строке
        {
            detArray[0][0] = array[0 + i][0 + j];
            detArray[0][1] = array[0 + i][1 + j];
            detArray[1][0] = array[1 + i][0 + j];
            detArray[1][1] = array[1 + i][1 + j];

            nextArray[i][j] = calcDeterminant(detArray);

        }
    }

    return nextArray;
}
0

There are 0 answers