Hello. I need to create a dynamic three-dimensional array. the fact is that I don't know the size of the array at the beginning. and recognize them later in one of the functions. and in one of the same functions I need to set the values ​​of the elements of this array. I think to do it through vectors. I have a class in which I declare a three-dimensional vector

class Base { private: static std::vector<std::vector<std::vector<unsigned char> > > mas; static void func1(); static void func2(); ... } 

and in one of the functions, as I recognize the size of the array, I change it through resize. those. for one dimension I do it (for example)

 int nj=14; mas.resize(nj); 

Generally do through resize is suitable for this task? I get this error:

 Error 194 error LNK2001: unresolved external symbol "private: static class std::vector<unsigned char,class std::allocator<unsigned char> > environment::mas" (?mas@environment@ @2V ?$vector@EV?$allocator@E @std @@ @std @ @A ) C:\Users\jh\Desktop\App.obj MyFirstApp Error 195 error LNK1120: 1 unresolved externals 
  • @ Dexter384, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

2 answers 2

The error is because the object of the static class is not created, respectively, the variable "mas" is not created, but only an uninitialized reference to it, so you need to duplicate it in

 static std::vector<std::vector<std::vector<unsigned char> > > Base::mas; 
    • Yes, through resize exactly what you need. But do not forget to change the size and nested arrays too.
    • No, the link error is not due to resize. Give the full text of the error.

    You already had a similar problem: Declaring a string in a class . This is solved the same way.

    Update

    Here is the documentation with examples .

    • Updated post with a complete error - Dexter384
    • so there is an error in that I did not take out the initialization from the string. and here what needs to be taken out? - Dexter384
    • Thank you) It turned out that in the class I just declared a vector, and I had to initialize it with std :: vector <unsigned char> environment :: mas; - Dexter384