C++ N nested vectors at runtime
问题 In C++ (with or without boost), how can I create an N dimensional vectors where N is determined at runtime? Something along the lines of: PROCEDURE buildNVectors(int n) std::vector < n dimensional std::vector > *structure = new std::vector< n dimensional std::vector >() END If passed 1, a vector would be allocated. If passed 2, a 2d nested matrix would be allocated. If passed 3, a 3d cube is allocated. etc. 回答1: Unfortunately you will not be able to do this. A std::vector is a template type