c ++中的赋值运算符删除内存

时间:2015-06-10 18:05:18

标签: c++

我正在尝试在分配新内存之前先删除内存,但我不知道如何制作,并且在尝试调整矩阵时遇到一个问题。

body { background-color: black; }

.arrow {
    position: absolute;
    bottom: 10px;
    left: 50%;
    margin-left: -20px;
    width: 40px;
    height: 40px;
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNi4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iNTEycHgiIGhlaWdodD0iNTEycHgiIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA1MTIgNTEyIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGw9IiNGRkZGRkYiIGQ9Ik0yOTMuNzUxLDQ1NS44NjhjLTIwLjE4MSwyMC4xNzktNTMuMTY1LDE5LjkxMy03My42NzMtMC41OTVsMCwwYy0yMC41MDgtMjAuNTA4LTIwLjc3My01My40OTMtMC41OTQtNzMuNjcyICBsMTg5Ljk5OS0xOTBjMjAuMTc4LTIwLjE3OCw1My4xNjQtMTkuOTEzLDczLjY3MiwwLjU5NWwwLDBjMjAuNTA4LDIwLjUwOSwyMC43NzIsNTMuNDkyLDAuNTk1LDczLjY3MUwyOTMuNzUxLDQ1NS44Njh6Ii8+DQo8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNMjIwLjI0OSw0NTUuODY4YzIwLjE4LDIwLjE3OSw1My4xNjQsMTkuOTEzLDczLjY3Mi0wLjU5NWwwLDBjMjAuNTA5LTIwLjUwOCwyMC43NzQtNTMuNDkzLDAuNTk2LTczLjY3MiAgbC0xOTAtMTkwYy0yMC4xNzgtMjAuMTc4LTUzLjE2NC0xOS45MTMtNzMuNjcxLDAuNTk1bDAsMGMtMjAuNTA4LDIwLjUwOS0yMC43NzIsNTMuNDkyLTAuNTk1LDczLjY3MUwyMjAuMjQ5LDQ1NS44Njh6Ii8+DQo8L3N2Zz4=);
    background-size: contain;
}

.bounce {
  -webkit-animation: bounce 2s infinite;
}

@-webkit-keyframes bounce {
    0%       { bottom:5px; }
    25%, 75% { bottom:15px; }
    50%      { bottom:20px; }
    100%     { bottom:0; }
}

例如(调整大小)

Matrix & operator=(const Matrix &B){            
            row = B.row;
            col = B.col;

            if (matrix==0){
                matrix = new int*[row];
                for (int i = 0; i < row; ++i)
                    matrix[i] = new int[col];
            }
            for (int i = 0; i < row; i++) {
                for (int j = 0; j < col; j++) {                 
                    matrix[i][j] = B.matrix[i][j];
                }
            }   
        return *this;

    }

谢谢你&amp;最好的问候

1 个答案:

答案 0 :(得分:2)

在每行上使用HoughCircles( greyGB, // Mat input source circles, // vector<vec3f> output vector that stores sets of 3 values: x_{c}, y_{c}, r for each detected circle. CV_HOUGH_GRADIENT, // detection method 1, // The inverse ratio of resolution (size of image / int) grey.rows / 8, // minimum distance between center of two circles 120, // Upper threshold for the internal Canny edge detector (should be 3x next number) 40, // Threshold for center detection (minimum number of votes) (lower this if no circles detected) 12, // Minimum radius to be detected. If unknown, put zero as default. 80 // Maximum radius to be detected. If unknown, put zero as default ); ,然后在矩阵上使用。

delete[]

请注意,这不会复制源矩阵的内容。需要另一个循环

if (matrix!=NULL){
    for (int i = 0; i < row; ++i)
        delete[] matrix[i];
    delete[] matrix;
}
row = B.row;
col = B.col;
matrix = new int*[row];
for (int i = 0; i < row; ++i)
    matrix[i] = new int[col];