c++ - 使用类 Visual C++ 2010

标签 c++ winforms visual-studio-2010 class

我是 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> Generating Code...
1>CardsOne.obj : error LNK2028: unresolved token (0A000013) "public: __clrcall Deck::~Deck(void)" (??1Deck@@$$FQAM@XZ) referenced in function "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) referenced in function "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>C:\Users\Bob K\Documents\Visual Studio 2010\Projects\CardsOne\Debug\CardsOne.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

如果有人能给我任何帮助,我将不胜感激

最佳答案

定义你的析构函数,也许在头文件中,或者如果你不使用它,甚至不要写 ~Deck();

关于c++ - 使用类 Visual C++ 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18729612/

相关文章:

Python套接字未从C++ Boost asio接收所有数据

mysql - Visual Studio 2015 添加数据源时出现“您已经有一个可用的连接”错误

visual-studio - 是否可以通过 Visual Studio IDE 中的键盘快捷键关闭左下面板?

c++ - 使用类模板的问题

c++ - 为什么函数调用比根据 gprof 执行的代码花费的时间长得多?

c++ - c++ 可执行文件的不同 linux 发行版的问题

c++ - 在 C++11 使用声明中是否允许/需要 "typename"?

c# - 如何填充多列列表框

c# - 在没有数据库连接的情况下使用 Entity Framework 类

c++ - parallel_for 函数导致内存泄漏(有时)