简体   繁体   English

简单的C ++卡程序。 未知错误

[英]Simple C++ Card Program. Unknown Error

Ok so I am new to C++ and trying to write I simple program that is a deck of cards. 好的,所以我是C ++的新手,并尝试编写一个简单的程序,即一副纸牌。 But I get the errors: "unresolved externals". 但是我得到了错误:“未解决的外部条件”。 I have a feeling it has something to do with the instantiation in the constructor. 我觉得它与构造函数中的实例化有关。 A quick look would be appreciated. 快速浏览将不胜感激。

#include "Card.h"
#include "Deck.h"

Deck:: Deck()
{
  this -> currentCard=0;

  this -> index = 0;

    for(int i=0;i<4;i++)
    {
        for(int j =0; j < 13;j++)
       {
          deck[index].setVal(i);
      deck[index].setSuit (j);
          index++;
        }
    }
 }


void Deck::shuffle()
{
  //implementation
  }
Card Deck:: dealCard()
{
  //implementation
   }


int main (){}

my header file is: 我的头文件是:

#include "Card.h"

class Deck
{
public:
Deck();
void shuffle();
Card dealCard();




private:
Card deck [52];
int currentCard;
int index;
};

It error means that you have unresolved external symbols . 错误表示您有未解析的外部符号

Now Symbols can be anything from Variables, Classes, Member functions. 现在, 符号可以是变量,类,成员函数中的任何一种。

Why they are unresolved is because may be some part of your code (or libraries that you are using) rely on these symbols and they are not being found because you are not linking the correct library or implementing them. 无法解析它们的原因是因为您的代码(或您正在使用的库)的某些部分可能依赖于这些符号,而未找到它们是因为您没有链接正确的库或实现它们。

Please try compiling all your source files and make sure there are no Symbols(Variables, Classes, Member Functions etc) missing. 请尝试编译所有源文件,并确保不丢失任何符号(变量,类,成员函数等)。

Card class seems to be undeclared. Card类似乎未声明。 You probably want to do it in Card.h file. 您可能想要在Card.h文件中执行此操作。 You can forward-declare it by simply typing class Deck; 您可以通过简单地键入class Deck;来向前声明它class Deck; , but remember it's just a place-holder that must be resolved somewhere anyway. ,但请记住,它只是一个占位符,无论如何都必须在某个地方解决它。

Usually 'Unresolved externals' points to the unresolved symbol: 通常,“未解决的外部因素”指向未解决的符号:

error LNK2001: unresolved external symbol "the symbol that wasn't resolved" 错误LNK2001:未解析的外部符号“未解析的符号”

This will show you what the linker is missing. 这将向您显示缺少的链接器。

Hope this helps, Yaron 希望这会有所帮助,Yaron

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM