현재 클래스의 카드 프로그램을 작성 중이며 컴파일러에서 상황이 선언되지 않는 문제가 발생합니다. 범위가있을 때 범위가 있으며 일부 항목은있을 때 선언되지 않습니다.또 다른 '이 범위에서 선언되지 않은'문제가 선언되었을 때
Card.h :
#ifndef _CARD_H
#define _CARD_H
#include <iostream>
#include <string>
using namespace std;
enum RANK{Joker, Ace = 1, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King}
enum SUIT{Clubs, Diamonds, Hearts, Spades}
class Card
{
private:
//Rank and Suit variables for all cards
int rank;
int suit;
public:
//Constructors
Card();
Card(int r, int s);
//Getters
int getRank();
int getSuit();
//Setters
void setRank(int r);
void setSuit(int s);
//toString
string toString();
};
#endif
Card.cpp :
#ifndef _CARD_H
#define _CARD_H
#include "Card.h"
#include <iostream>
#include <string>
using namespace std;
//Default constructor
Card::Card()
{
rank=Joker;
suit=Clubs;
}
//Constructor
Card::Card(int r, int s)
{
rank = r;
suit = s;
}
//Getters for rank and suit
int Card::getRank()
{
return rank;
}
int Card::getSuit()
{
return suit;
}
//Setters for rank and suit
void Card::setRank(int r)
{
rank = r;
}
void Card::setSuit(int s)
{
suit = s;
}
//toString function for output
string Card::toString()
{
string tempstring = ""; //list of if-else statements for what to add to the string that gets printed
if (rank == 0)
{
tempstring += "Joker";
goto stringEnd; //sends the process to the end of the list if rank is Joker so it doesn't attempt to add a suit to the card toString
}
else if (rank == 1)
tempstring += "Ace of ";
else if (rank == 2)
tempstring += "Two of ";
else if (rank == 3)
tempstring += "Three of ";
else if (rank == 4)
tempstring += "Four of ";
else if (rank == 5)
tempstring += "Five of ";
else if (rank == 6)
tempstring += "Six of ";
else if (rank == 7)
tempstring += "Seven of ";
else if (rank == 8)
tempstring += "Eight of ";
else if (rank == 9)
tempstring += "Nine of ";
else if (rank == 10)
tempstring += "Ten of ";
else if (rank == 11)
tempstring += "Jack of ";
else if (rank == 12)
tempstring += "Queen of ";
else if (rank == 13)
tempstring += "King of ";
if (suit == 0)
tempstring += "Clubs";
else if (suit == 1)
tempstring += "Diamonds";
else if (suit == 2)
tempstring += "Hearts";
else if (suit == 3)
tempstring += "Spades";
stringEnd:
return tempstring;
}
#endif
나는 그것이 바로 컴파일하지 왜 모르겠어요 여기에 코드입니다. 모든게 괜찮은 것 같습니다.
이것은 문제가되지 않지만 밑줄 뒤에 대문자 (_CARD_H)가 오는 이름과 두 개의 연속 된 밑줄이있는 이름은 구현에서 사용하기 위해 예약되어 있습니다. 코드에서 사용하지 마십시오. –