0

我是 VC++ 的新手,我正在尝试使用类。我的子例程作为直接代码运行良好,但是当我尝试在类中使用它时,我不断收到错误 这是头文件的代码。

            [using namespace std;
#ifndef Deck_h
#define Deck_h
class Deck
{
       public:
// Default constructor
Deck();
//Destructor
~Deck();
// access functions
//function1
// Member variables

int InDeck[53];
int OutDeck[53];



  };

 #endif

这是 .cpp 文件的代码

            #include "StdAfx.h"
    #include "Deck.h"
    #include <stdlib.h>
    #include <time.h>
    &Deck::Deck()

    { // start of Deck
        int InDeck[53];
        int OutDeck[53];
        int icard;
        int isuit=1;

        for(int i = 1; i<=52; i++)
            { // Begin For i
            icard = i % 13;
            if(icard ==  0){icard=13;}
            InDeck[i] = isuit * 1000 + icard;
            OutDeck[i] = 0;
            if(icard == 13 ){isuit ++;}
        }// end of for i...
        // Randomize InDeck into OutDeck
        int t = 0;  
        srand(time_t(NULL));
        for(int j = 1; j<=52; j++)
        { // begin for j
            icard = rand() % 52 +1;
            t = 0;
            while (OutDeck[icard] >= 1000)
            { // while
                t++;
                icard = rand() % 52 +1;
                if(t > 10)
                { // Don't take too long shuffling
                    for(int k=1; k<=52; k++)
                    { // put card in first empty slot
                        if(OutDeck[k] < 1000) {
                            icard = k;
                            t  = 0;
                            break;
                        } // empty slot found
                    }  //end of for k... 
                    } // end of if t > 1000

            } //end while
            OutDeck[icard] = InDeck[j];

        } // end for j  
    } // end of Deck

这是使用该类的代码

          Deck mydeck;

array<PictureBox ^, 1> ^ pix = gcnew array<PictureBox ^, 1>(10);
pix[0] = this->pb1;
pix[1] = this->pb2;
pix[2] = this->pb3;
pix[3] = this->pb4;
pix[4] = this->pb5;
pix[5] = this->pb6;
pix[6] = this->pb7;
pix[7] = this->pb8;
pix[8] = this->pb9;
pix[9] = this->pb10;


for(int p  = 1; p<= 10; p++)
{pix[p-1]->Image = Bitmap::FromFile("c:\\users\\Bob K\\Documents\\pictures\\" +             System::Convert::ToString(mydeck.OutDeck[p]) + ".bmp"); 
}

        } //End of Form1 load

这些是错误消息

1> Deck.cpp
1> 生成代码...
1>CardsOne.obj : error LNK2028: unresolved token (0A000013) "public: __clrcall Deck::~Deck(void)" (??1Deck@@$$FQAM@XZ ) 在函数“private: void __clrcall CardsOne::Form1::Form1_Load(class System::Object ^,class System::EventArgs ^)”中引用 (?Form1_Load@Form1@CardsOne@@$$FA$AAMXP$AAVObject@System @@P$AAVEventArgs@4@@Z)
1>CardsOne.obj : error LNK2019: unresolved external symbol "public: __clrcall Deck::~Deck(void)" (??1Deck@@$$FQAM@XZ) 在中引用函数“私有:void __clrcall CardsOne::Form1::Form1_Load(类 System::Object ^,类 System::EventArgs ^)”(?Form1_Load@Form1@CardsOne@@$$FA$AAMXP$AAVObject@System@@P $AAVEventArgs@4@@Z)
1>C:\Users\Bob K\Documents\Visual Studio 2010\Projects\CardsOne\Debug\CardsOne.exe : 致命错误 LNK1120: 2 unresolved externals
========== Build: 0 成功,1 失败, 0 最新, 0 跳过 ==========

我将不胜感激任何人都可以给我的帮助

4

2 回答 2

1

定义你的析构函数,可能在标题中,或者~Deck();如果你不使用它甚至不写

于 2013-09-10T22:14:06.827 回答
1

链接器说“您在 .h 文件中告诉我在某处会有一个~Deck函数,但我找不到它的定义。”

由于您没有使用析构函数,因此只需~Deck();从标题中删除即可。

于 2013-09-10T22:22:35.493 回答