Error with VS C++ 2010



我的VS 2010 C++ Express有问题,每次我开始构建和调试时,我都有项目,他给了我这个错误:https://i.stack.imgur.com/6cUF1.png问题是我的朋友有相同的项目和相同的代码,并且它对他有用,所以我认为代码中没有问题,但在 VS 中我真的需要你的帮助,谢谢你注意:我试图重新建立,但同样的问题

件 :

#include "Joueur.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Piece
{
private:
    Joueur^ proprietaire;  // pointeur vers joueur
    int ligne;
    int col;
    String^ label;
    Image^ symbole;
public:
    Piece();
    Piece(Joueur^ proprietaire, int ligne, int col, String^ label, Image^ symbole);
    property Joueur^ propProprietaire {
        Joueur^ get();
        void set(Joueur^);
    }
    property int propLigne {
        int get();
        void set(int);
    }
    property int propCol {
        int get();
        void set(int);
    }
    property String^ propLabel {
        String^ get();
        void set(String^);
    }
    property Image^ propSym {
        Image^ get();
        void set(Image^);
    }
};

件.cpp:

#include "stdafx.h"
#include "Piece.h"
Piece::Piece() {
    this->proprietaire = nullptr;
    ligne = 0;
    col = 0;
    label = nullptr;
    symbole = nullptr;
}
Piece::Piece(Joueur^ prop, int L, int C, String^ La, Image^ Sym)
{
    this->proprietaire = prop;
    ligne = L;
    col = C;
    label = La;
    symbole = Sym;
}
Joueur^ Piece::propProprietaire::get() {
    return proprietaire;
}
void Piece::propProprietaire::set(Joueur^ prop) {
    this->proprietaire = prop;
}
int Piece::propLigne::get() {
    return ligne;
}
void Piece::propLigne::set(int L) {
    ligne = L;
}
int Piece::propCol::get() {
    return col;
}
void Piece::propCol::set(int C) {
    col = C;
}
String^ Piece::propLabel::get() {
    return label;
}
void Piece::propLabel::set(String^ L) {
    label = L;
}
Image^ Piece::propSym::get() {
    return symbole;
}
void Piece::propSym::set(Image^ IMG) {
    symbole = IMG;
}

Echecs.cpp:

#include "stdafx.h"
#include "Piece.h"
#include "Form1.h"
#include "Form2.h"
using namespace Echecs;
namespace Echecs {
    void Form1::Quitter(Object^  sender, EventArgs^  e) {
        Close();
    }
    void Form2::btnAnnuler_Click(Object^  sender, EventArgs^  e) {
        Close();
    }
    void Form2::btnValider_Click(Object^  sender, EventArgs^  e) {
        Form1::set(tbJoueur1->Text);
        Form1::set2(tbJoueur2->Text);
        Close();
    }
    void Form1::Menu_NouvellePartie(Object^  sender, EventArgs^  e) {
        Form2^ frm = gcnew Form2();
        frm->ShowDialog();
    }
    void Form1::NouvellePartie() {
        ListeJoueurs = gcnew array<Joueur^>(2);  // Instancier un tableau à 1 dimensio, de 2 éléménts
        ListeJoueurs[0] = gcnew Joueur("Joueur 1", lbCoups1);
        ListeJoueurs[1] = gcnew Joueur("Joueur 2", lbCoups2);
        lbJoueur1->Text = ListeJoueurs[0]->propNom;
        lbJoueur2->Text = ListeJoueurs[1]->propNom;
        grille = gcnew array<Piece^, 2>(8,8);  // Instancier un tableau à 2 dimensions, de taille 8x8
        for(int i=0 ; i<8 ; i++)
            for(int j=0 ; j<8 ; j++)
                grille[i,j] = nullptr;  // Initialiser chacun de ses éléments à NULL
        // Initialisation de la grille pour le Joueur 1 (ligne 0 & 1)
        grille[0,0] = gcnew Piece(ListeJoueurs[0], 0, 0, "Tour", Pieces->Images[0]);
        grille[0,1] = gcnew Piece(ListeJoueurs[0], 0, 1, "Cavalier", Pieces->Images[1]);
        grille[0,2] = gcnew Piece(ListeJoueurs[0], 0, 2, "Fou", Pieces->Images[2]);
        grille[0,3] = gcnew Piece(ListeJoueurs[0], 0, 3, "Roi", Pieces->Images[3]);
        grille[0,4] = gcnew Piece(ListeJoueurs[0], 0, 4, "Dame", Pieces->Images[4]);
        grille[0,5] = gcnew Piece(ListeJoueurs[0], 0, 5, "Fou", Pieces->Images[2]);
        grille[0,6] = gcnew Piece(ListeJoueurs[0], 0, 6, "Cavalier", Pieces->Images[1]);
        grille[0,7] = gcnew Piece(ListeJoueurs[0], 0, 7, "Tour", Pieces->Images[0]);
        for(int j=0 ; j<8 ; j++)
            grille[1,j] = gcnew Piece(ListeJoueurs[0], 1, j, "Pion", Pieces->Images[5]);
        // Initialisation de la grille pour le Joueur 2 (ligne 6 & 7)
        grille[7,0] = gcnew Piece(ListeJoueurs[1], 7, 0, "Tour", Pieces->Images[6]);
        grille[7,1] = gcnew Piece(ListeJoueurs[1], 7, 1, "Cavalier", Pieces->Images[7]);
        grille[7,2] = gcnew Piece(ListeJoueurs[1], 7, 2, "Fou", Pieces->Images[8]);
        grille[7,3] = gcnew Piece(ListeJoueurs[1], 7, 3, "Roi", Pieces->Images[9]);
        grille[7,4] = gcnew Piece(ListeJoueurs[1], 7, 4, "Dame", Pieces->Images[10]);
        grille[7,5] = gcnew Piece(ListeJoueurs[1], 7, 5, "Fou", Pieces->Images[8]);
        grille[7,6] = gcnew Piece(ListeJoueurs[1], 7, 6, "Cavalier", Pieces->Images[7]);
        grille[7,7] = gcnew Piece(ListeJoueurs[1], 7, 7, "Tour", Pieces->Images[6]);
        for(int j=0 ; j<8 ; j++)
            grille[6,j] = gcnew Piece(ListeJoueurs[1], 6, j, "Pion", Pieces->Images[11]);
        /* Pion, Pion, Pion, Pion, Pion, Pion, Pion, Pion
           Tour, Cavalier, Fou, Roi, Dame, Fou, Cavalier, Tour */
        // Instanciation des cases du tableau Tab
        Tab[0,0] = case_0_0;     Tab[0,1] = case_0_1;     Tab[0,2] = case_0_2;     Tab[0,3] = case_0_3;
        Tab[0,4] = case_0_4;     Tab[0,5] = case_0_5;     Tab[0,6] = case_0_6;     Tab[0,7] = case_0_7;
        Tab[1,0] = case_1_0;     Tab[1,1] = case_1_1;     Tab[1,2] = case_1_2;     Tab[1,3] = case_1_3;
        Tab[1,4] = case_1_4;     Tab[1,5] = case_1_5;     Tab[1,6] = case_1_6;     Tab[1,7] = case_1_7;
        Tab[2,0] = case_2_0;     Tab[2,1] = case_2_1;     Tab[2,2] = case_2_2;     Tab[2,3] = case_2_3;
        Tab[2,4] = case_2_4;     Tab[2,5] = case_2_5;     Tab[2,6] = case_2_6;     Tab[2,7] = case_2_7;
        Tab[3,0] = case_3_0;     Tab[3,1] = case_3_1;     Tab[3,2] = case_3_2;     Tab[3,3] = case_3_3;
        Tab[3,4] = case_3_4;     Tab[3,5] = case_3_5;     Tab[3,6] = case_3_6;     Tab[3,7] = case_3_7;
        Tab[4,0] = case_4_0;     Tab[4,1] = case_4_1;     Tab[4,2] = case_4_2;     Tab[4,3] = case_4_3;
        Tab[4,4] = case_4_4;     Tab[4,5] = case_4_5;     Tab[4,6] = case_4_6;     Tab[4,7] = case_4_7;
        Tab[5,0] = case_5_0;     Tab[5,1] = case_5_1;     Tab[5,2] = case_5_2;     Tab[5,3] = case_5_3;
        Tab[5,4] = case_5_4;     Tab[5,5] = case_5_5;     Tab[5,6] = case_5_6;     Tab[5,7] = case_5_7;
        Tab[6,0] = case_6_0;     Tab[6,1] = case_6_1;     Tab[6,2] = case_6_2;     Tab[6,3] = case_6_3;
        Tab[6,4] = case_6_4;     Tab[6,5] = case_6_5;     Tab[6,6] = case_6_6;     Tab[6,7] = case_6_7;
        Tab[7,0] = case_7_0;     Tab[7,1] = case_7_1;     Tab[7,2] = case_7_2;     Tab[7,3] = case_7_3;
        Tab[7,4] = case_7_4;     Tab[7,5] = case_7_5;     Tab[7,6] = case_7_6;     Tab[7,7] = case_7_7;
        for(int i=0 ; i<8 ; i++)
            for(int j=0 ; j<8 ; j++) {
                Affichage(grille[i,j]);
                Tab[i,j]->BackColor = Color::Transparent;
            }
    }
    void Form1::Affichage(Piece^ P) {
        int L = P->propLigne;
        int C = P->propCol;
        Tab[L,C]->Image = P->propSym;
    }
    void Form1::set(String^ n) {
        lbJoueur1->Text = n;
    }
    void Form1::set2(String^ n)
    {
        lbJoueur2->Text=n;
    }
    void Form1::Deplacer(Object^  sender, EventArgs^  e) {
        Point coordonnees = (Point)(((PictureBox^)sender)->Tag) ;
        int L = coordonnees.X;     int C = coordonnees.Y;
        if ((grille[L,C] != nullptr) && (NClick != 1)) {
            NClick = 1;   L1=L;   C1=C;
            Tab[L,C]->BackColor = Color::Yellow;
            Pc = grille[L,C];
            DeplacementAutorise(grille[L,C]);
        }
        else if ((grille[L,C] == nullptr) && (NClick == 1)) {
            Tab[L,C]->Image = Pc->propSym;
            grille[L,C] = Pc;
            Tab[L1,C1]->Image = nullptr;
            grille[L1,C1] = nullptr;
            NClick = 0;
            for(int i=0 ; i<8 ; i++)
                for(int j=0 ; j<8 ; j++)
                    Tab[i,j]->BackColor = Color::Transparent;
        }
        else if ((grille[L,C] != nullptr) && (NClick == 1)) {
            for(int i=0 ; i<8 ; i++)
                for(int j=0 ; j<8 ; j++)
                    Tab[i,j]->BackColor = Color::Transparent;
            Tab[L,C]->BackColor = Color::Yellow;
            Pc = grille[L,C];
            DeplacementAutorise(grille[L,C]);
        }
    }
    void Form1::DeplacementAutorise(Piece^ P) {
        int L = P->propLigne;     int C = P->propCol;
        String^ Lab = P->propLabel;
        if (Lab == "Cavalier") {
            if ((L+2<=7) && (C+1<=7))
                Tab[L+2,C+1]->BackColor = Color::Cyan;
            if ((L+1<=7) && (C+2<=7))
                Tab[L+1,C+2]->BackColor = Color::Cyan;
            if ((L+2<=7) && (C-1>=0))
                Tab[L+2,C-1]->BackColor = Color::Cyan;
            if ((L+1<=7) && (C-2>=0))
                Tab[L+1,C-2]->BackColor = Color::Cyan;
            if ((L-1>=0) && (C+2<=7))
                Tab[L-1,C+2]->BackColor = Color::Cyan;
            if ((L-2>=0) && (C+1<=7))
                Tab[L-2,C+1]->BackColor = Color::Cyan;
            if ((L-1>=0) && (C-2>=0))
                Tab[L-1,C-2]->BackColor = Color::Cyan;
            if ((L-2>=0) && (C-1>=0))
                Tab[L-2,C-1]->BackColor = Color::Cyan;
        }
        if (Lab == "Pion") {
            if (grille[L+1,C] == nullptr)
                Tab[L+1,C]->BackColor = Color::Cyan;
        }
        if (Lab == "Fou");

        /*if ((L+1<=7) && (C+1<=7))
          if (grille[L+1,C+1] == nullptr) {
          while ((L+1<=7) && (C+1<=7)) {
          Tab[L+1,C+1]->BackColor = Color::Cyan;
          L++; C++;
          }}
          if ((L+1<=7) && (C-1>=0)) {
          while ((L+1<=7) && (C-1>=0)) {
          Tab[L+1,C-1]->BackColor = Color::Cyan;
          L++; C++;
          }}*/


    }
    void Form1::Form1_Load(Object^  sender, EventArgs^  e) {
        NouvellePartie();
    }
}

int main(array<System::String ^> ^args)
{
    // Activation des effets visuels de Windows XP avant la création de tout contrôle
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    // Créer la fenêtre principale et l'exécuter
    Application::Run(gcnew Form1());
    return 0;
}

这很可能是因为格栅矩阵中第 2、3、4、5中的所有元素都初始化NULLs (Form1::NouvellePartie )。

解决 方案:

  • 初始化格栅矩阵中的所有元素,作为 Piece:调用默认构造函数而不是分配 nullptrgrille[i, j] = gcnew Piece();
  • 修改Form1::Afichage以测试 P 是否存在

最新更新