从main()C ++中的不同.cpp调用函数

时间:2017-10-07 23:23:00

标签: c++

我正在尝试为一个类编写一个Black Jack游戏,我们需要使用头文件和多个.cpp文件。我已经找到了代码,但是在调用main函数中的函数时遇到了问题。代码发布在下面。它都在同一个文件夹中,所以我不认为这是问题所在。我正在尝试学习如何在我的main(BlackJackMike.cpp)中调用任何这些函数。我一直得到的错误是

“LNK2019未解析的外部符号”public:int __thiscall Card :: getcValue(void)const“(?getcValue @ Card @@ QBEHXZ)在函数_main BlackJackMike C:\ Users \ merisman96 \ source \ repos \ BlackJackMike \ BlackJackMike中引用\ BlackJackMike.obj“

我已经搜索过但仍然无法解决此错误。任何帮助都会很棒!!! 感谢!!!

O我也在使用Visual Studio 2017我不知道这是否意味着什么。

BlackJackMike.cpp 我的主要在哪里

#include "stdafx.h"
//#include "Deck.h"
#include "Card.h"

using namespace std;
int main()
{
    Card C; //not to sure what happens here but I know I need it
    C.getcValue(); //Attempting to call the function getcValue() from my card class

    return 0;
}

Card.h

#pragma once
#include <iostream>
#include <vector>
#include <algorithm> 
#include <ctime>
#include <sstream>
#include <string>
#include <limits>
#include <random>

using namespace std;

class Card {
    char card;
    int cValue;
    int cSuite;
    string cSName;
    bool isCardMade;
public:
    Card() {};
    Card(char, int);
    //Card(const Card&);
    int assignCV();
    int getcValue()const;
    int getCSuite()const;
    string getCName()const;
    bool getIsCardMade()const;
    char getCard()const;
    void setIsCardMade(bool x);
    void nameCard();
};

Card.cpp

#include "Card.h"

Card::Card(char Value, int suite)
{
    card = Value;
    cValue = assignCV();
    cSuite = suite;
    isCardMade = false;
}

//Card::Card(const Card & card1)
//{
//  card = card1.getCard();
//  cValue = card1.getcValue();
//  cSuite = card1.getCSuite();
//  cSName = card1.getCName();
//  isCardMade = card1.getIsCardMade();
//}

int Card::assignCV()
{
    if (card == 'A')
        return 11;

    else if (card == 'T' || card == 'J' || card == 'Q' || card == 'K') // here we see 'T' as 10 being assigned the value of 10
        return 10;
    else
        return (card - '0');
}

int Card::getcValue() const
{
    cout << "Ran getcValue" << endl;
    return cValue;
}

int Card::getCSuite() const
{
    return cSuite;
}

string Card::getCName() const
{
    return cSName;
}

bool Card::getIsCardMade() const
{
    return isCardMade;
}

char Card::getCard() const
{
    return card;
}

void Card::setIsCardMade(bool x)
{
    isCardMade = x;
}

void Card::nameCard()
{
    switch (cSuite) {
    case 0: cSName = "Spades";
        break;
    case 1: cSName = "Clubs";
        break;
    case 2: cSName = "Hearts";
        break;
    case 3: cSName = " Diamonds";
        break;
    }
    if (card == 'A')
        cout << "Ace";
    else if (card == 'J')
        cout << "Jack";
    else if (card == 'Q')
        cout << "Queen";
    else if (card == 'K')
        cout << "king";
    else if (card == 'T') // We see that once again the 10 is stored as a 'T'
        cout << "10"; // and that it is being printed as '10'
    else
        cout << cValue;
    cout << " of " << cSName << endl;
}

0 个答案:

没有答案