0

我的代码有一些问题,我不知道如何解决它。

当我尝试通过调试选项编译它时,出现此错误: HEAP[Tetris.exe]: Invalid address specified to RtlValidateHeap(000001C1F4BE0000, 0000005257B7F728)


//Tetrino.h
#pragma once
#include <ctime>
#include <cstdlib>


extern int n_shp[16];
extern int n_r_shp[16];
extern int l_shp[16];
extern int l_r_shp[16];
extern int line_shp[16];
extern int t_shp[16];
extern int sqr_shp[16];



enum tiles {tN = 1 , tN_r, tL, tL_r, tLine, tT, tSqr};

template <tiles T>
class Tile
{
public:
    int* shp;
    Tile();
    ~Tile() { delete[] shp; };
private:
    void allocate_space();
};

template <tiles T>
void Tile<T>::allocate_space()
{
    shp = nullptr;
    shp = new int[16];
}


//Tetrino.cpp

#include "Tetrinos.h"


int n_shp[16] = {
     0,0,1,0,
     0,1,1,0,
     0,1,0,0,
     0,0,0,0 };
int n_r_shp[16] = {
     0,2,0,0,
     0,2,2,0,
     0,0,2,0,
     0,0,0,0    };
int l_shp[16] = {
     3,3,3,0,
     3,0,0,0,
     0,0,0,0,
     0,0,0,0 };
int l_r_shp[16] = {
    4,0,0,0,
    4,4,4,0,
    0,0,0,0,
    0,0,0,0 };
int line_shp[16] = {
     5,0,0,0,
     5,0,0,0,
     5,0,0,0,
     5,0,0,0 };
int t_shp[16] = {
     6,6,6,0,
     0,6,0,0,
     0,0,0,0,
     0,0,0,0 };
int sqr_shp[16] = {
     7,7,0,0,
     7,7,0,0,
     0,0,0,0,
     0,0,0,0 };





template <>
Tile<tN>::Tile()
{
    allocate_space();
    shp = n_shp;
}
template <>
Tile<tN_r>::Tile()
{
    allocate_space();
    shp = n_r_shp;
}
template <>
Tile<tL>::Tile()
{
    allocate_space();
    shp = l_shp;
}
template <>
Tile<tL_r>::Tile()
{
    allocate_space();
    shp = l_r_shp;
}
template <>
Tile<tLine>::Tile()
{
    allocate_space();
    shp = line_shp;
}
template <>
Tile<tT>::Tile()
{
    allocate_space();
    shp = t_shp;
}
template <>
Tile<tSqr>::Tile()
{
    allocate_space();
    shp = sqr_shp;
}

//Tetris.cpp


#include"Tetrino.h"
#include<iostream>

extern int n_shp[16];
extern int n_r_shp[16];
extern int l_shp[16];
extern int l_r_shp[16];
extern int line_shp[16];
extern int t_shp[16];
extern int sqr_shp[16];


int main(int argv, char* argc[])
{
    Tile<tLine> A;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++)
            std::cout << A.shp[j + i * 4];
        std::cout << std::endl;
    }
    return EXIT_SUCCESS;
}

如果您向我解释如何解决此错误,我将不胜感激

4

0 回答 0