这是标题
#ifndef CARD_H
#define CARD_H
#include <iostream>
#include <ios>
#include <string>
using namespace std;
class Card {
friend class deck;
friend class Hand;
private:
// assigns ranks to a string to greatly shorten the necessary array
const string ourRanks[13] = { "2", "3", "4",
"5", "6", "7", "8", "9", "10", "Jack",
"Queen", "King", "Ace" };
// assigns suits to a string to greatly shorten the necessary array
const string ourSuits[5] = { "Clubs", "Diamonds", "Hearts", "Spades" };
// stores the rank
int rank;
// stores the suit
int suit;
// card, stores string card for usage
string card;
public:
Card() {
this -> rank = 0;
this -> suit = 0;
this -> card = "The Two of clubs";
return;
}
// Card constructor
Card(int ranks, int suits);
// gets rank and suit
int getRank(int ranks);
int getSuit(int suits);
// defines the value
int getValue();
// gets the highest and lowest values
int getHighValue();
int getLowValue();
// finds and declares the rank and suit
bool validRank(int ranks);
bool validSuit(int suits);
// creates a card
bool equals();
// exports the card to be used
string newCard();
// These create the numerical representation of the card ranks
const int TWO = 0;
const int THREE = 1;
const int FOUR = 2;
const int FIVE = 3;
const int SIX = 4;
const int SEVEN = 5;
const int EIGHT = 6;
const int NINE = 7;
const int TEN = 8;
const int JACK = 9;
const int QUEEN = 10;
const int KING = 11;
const int ACE = 12;
// These create the numerical representation of the card suits
const int CLUB = 0;
const int DIAMONDS = 1;
const int HEARTS = 2;
const int SPADES = 3;
};
#endif
这是cpp文件
#include <iostream>
#include <ios>
#include <cmath>
#include <string>
#include <assert.h>
#include <stdio.h>
using namespace std;
#include "Card.h"
Card::Card(int ranks, int suits) {
this -> rank = getRank(ranks);
this -> suit = getSuit(suits);
assert(validSuit(suits));
assert(validRank(ranks));
this->card = newCard();
return;
}
int Card :: getRank(int ranks) {
rank = ranks;
return rank;
}
int Card :: getSuit(int suits) {
suit = suits;
return suit;
}
int Card ::getValue() {
if (rank == TWO) {
return 2;
}
else if (rank == THREE) {
return 3;
}
else if (rank == FOUR) {
return 4;
}
else if (rank == FIVE) {
return 5;
}
else if (rank == SIX) {
return 6;
}
else if (rank == SEVEN) {
return 7;
}
else if (rank == EIGHT) {
return 8;
}
else if (rank == NINE) {
return 9;
}
else if (rank == TEN) {
return 10;
}
else if (rank > TEN && rank != ACE) {
return 10;
}
else {
return -1;
}
}
int Card ::getHighValue() {
int high = getValue();
if (high == -1) {
return 11;
}
else {
return high;
}
}
int Card ::getLowValue() {
int low = getValue();
if (low == -1) {
return 1;
}
else {
return low;
}
}
bool Card ::validRank(int ranks) {
if ((TWO <= ranks) && (ACE >= ranks)) {
return true;
}
else {
return false;
}
}
bool Card ::validSuit(int suits) {
if ((CLUB <= suit) && (SPADES >= suits)) {
return true;
}
else {
return false;
}
}
bool Card :: equals() {
Card otherCard(rank, suit);
if ((suit == otherCard.suit) && (rank == otherCard.rank)) {
return true;
}
else {
return false;
}
}
string Card::newCard() {
card = ourRanks[getRank(rank)];
card.append(" of ");
card.append(ourSuits[getSuit(suit)]);
return card;
}
这是错误:
Severity Code Description Project File Line
Error C1001 An internal error has occurred in the compiler. {Project4} c:\users\thelazyogre\documents\visual studio 2015\projects\{project4}\card.cpp 23
答案 0 :(得分:0)
很抱歉浪费你的时间,我发现了问题,它现在正常工作,我习惯了很多我的数组的初始化我通过重新调整它的参数来修复它
答案 1 :(得分:0)
这是编译器错误。我在VS2015中尝试了相同的代码并收到了消息:
1>------ Rebuild All started: Project: scratch, Configuration: Debug Win32 ------
1> scratch.cpp
1>E:\Code\VS2015\scratch\scratch\scratch.cpp : fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 246)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
正如Patrick Duggin的回答中指出的那样,它与数组初始化有关。我的最小可重现性如下:
#include <string>
class X
{
std::string strings[2] = { "first" };
};
int main()
{
X x;
}
上面的代码会产生相同的错误。这是有效的C ++代码。调整阵列大小或向阵列添加另一个初始化程序是该错误的解决方法。
我无法使用不同类型的数组重现错误。我没有动力去了解导致这种情况的确切内容std::string
。