数据无法打印到控制台

时间:2011-12-23 04:35:35

标签: visual-c++ memory-management runtime-error

所以,我想出了我的编译器/链接器错误。现在,我只是在打印到控制台时遇到问题。以下代表一个简单的测试,旨在生成一个简单的矩阵,然后将其数据打印到控制台。 我想知道为什么不将数据打印到控制台..

我也一定要发布我的源文件:

#include "GLMatrix.h"

namespace Graphics {

    GLMatrix::GLMatrix(int sizeX, int sizeY)
    {
        _sizeX = sizeX; 
        _sizeY = sizeY;
    }

    GLMatrix::~GLMatrix()
    {
        delete _pArray;
    }

    void GLMatrix::addColumnItem(int row, int column, long item) {
        _pArray[row][column] = item;
    }

    void GLMatrix::allocMatrix() {

        _pArray = new long*[_sizeX];

        for (int i = 0; i < _sizeX; ++i) {          
            _pArray[i] = new long[_sizeY];
        }

    }

    void GLMatrix::revertRowsByColumns() {

        long** columns = new long*[_sizeY];

        for (int col = 0; col < _sizeY; ++col) {
            columns[col] = new long[_sizeX];
            memmove(
                columns + col, 
                _pArray[_sizeX - col], 
                sizeof(_sizeX) - sizeof(col)
            );
        }   
    }

}

主要

#include <SDL.h>
#include <iostream>
#include "GLMatrix.h"


int main(int argc, char* argv[]) {

    //SDL_Init(SDL_INIT_EVERYTHING);

    //matrix test

    Graphics::GLMatrix* matrix = new Graphics::GLMatrix(3, 3);

    matrix->allocMatrix();

    int num_rows = matrix->getRowSize();
    int num_columns = matrix->getColumnSize();



    for (int row = 0; row < num_rows; ++row) {
        for (int col = 0; col < num_columns; ++col) {
            long i = static_cast<long>(col);
            matrix->addColumnItem(row,col, i);
            if ((row + 1) % 2 != 0) {
                std::cout << i << " ";
            } else {
                std::cout << "\n";
            }
        }   
    }

    //SDL_Quit();

    delete matrix;

    system("pause");

    return 0;
}

我的某些控制台输出

'OpenGL_01.exe': Loaded 'ImageAtBase0x4a6e0000', Loading disabled by Include/Exclude setting.
'OpenGL_01.exe': Unloaded 'ImageAtBase0x4a6e0000'
The program '[3324] OpenGL_01.exe: Native' has exited with code 0 (0x0).

我还是比较新的语言。

更新

我将行和列变量的数组和getter的分配切换为类似于以下内容:

matrix->allocMatrix();

int num_rows = matrix->getRowSize();
int num_columns = matrix->getColumnSize();

不幸的是,我仍然遇到同样的错误。

0 个答案:

没有答案
相关问题