0

I couldn't figure out how to resolve the decadence to pointers of the first element in arguments of type array on my code:

class environment
{
    private:

        struct espacoFisico             // Limite das coordenadas reais no objeto
        {
            double long absoluteX, absoluteY, absoluteZ;
            std::vector <struct globalTile> tensor(std::vector<struct globalTile>x(std::vector<struct globalTile> y));
            espacoFisico()
            {
                for (double long buildingX = 0; buildingX < absoluteX; ++buildingX)
                {
                    for (double long buildingY = 0; buildingY < absoluteY; ++buildingY)
                    {
                        for(double long buildingZ = 0; buildingZ < absoluteZ; ++buildingZ)
                        {
                            this->tensor[buildingX][buildingY][buildingZ].emplace_back(globalTile());
                        };
                    };
                };
            };
        };

So I'm getting what every newbie seems to get when trying to learn how to use a dynamic multidimensional vector of vectors:

environment.cpp: In constructor 'environment::espacoFisico::espacoFisico()':
environment.cpp:95:51: error: invalid types '<unresolved overloaded function type>[long double]' for array subscript
                             this->tensor[buildingX][buildingY][buildingZ].emplace_back(globalTile());
                                               ^

How would I be able to apply this (i.e. initialize the vector in the constructor), if I need the multidimensional vector called 'tensor' to be a member of the struct which is a member of the class?

1 Answers1

0

You've declared tensor as a function. To declare the array you want, you need to create a vector of vectors of vectors:

std::vector< std::vector< std::vector<globalTile>>> tensor;

All these vectors will be empty. You will need to allocate space for them before using them within your loops.

As for the compiler error, it is telling you that you can't use a long double variable as a subscript for a vector. buildingX etc should be an integer type (int or size_t being commonly used).

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • Thank you for this answer. I made the loops for the purpose of allocating the space, as I have no way of knowing how much will be needed, plus I needed the tensor to be dynamic. Time for some refactoring. – Havoc Lamperouge Dec 01 '18 at 15:28