Line 1034: Char 9: runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator<int>>’ (stl_vector.h)

  adjacency-matrix, c++, matrix, runtime-error, stl

I am getting runtime error while running the following code on leetcode 48;

class Solution {
  public:
  void rotate(vector<vector<int>>& matrix)
  {vector<vector<int>>copy;
    for(int i=0;i<matrix.size();i++)
    {
        for(int j=0;j<matrix.size();j++)
        {
            copy[j][matrix.size()-i-1]=matrix[i][j];    
        }    
    }
    
    for(int i=0;i<matrix.size();i++)
    {
        for(int j=0;j<matrix.size();j++)
        {
            matrix[i][j]=copy[i][j];  
        }}
   
}};

as
Line 1034: Char 9: runtime error: reference binding to null pointer of type ‘std::vector<int, std::allocator>’ (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1043:9

Source: Windows Questions C++

LEAVE A COMMENT