我的card类不断出现编译器错误c1001
my card class keeps getting a compiler error c1001
这是标题
#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:usersthelazyogredocumentsvisual studio 2015projects{project4}card.cpp 23
很抱歉浪费你的时间,我解决了问题,它现在可以正常工作了,我习惯了对我的数组进行多次初始化,我通过重新调整它的参数的来修复它
这是一个编译器错误。我在VS2015中尝试了相同的代码,并收到消息:
1>------ Rebuild All started: Project: scratch, Configuration: Debug Win32 ------
1> scratch.cpp
1>E:CodeVS2015scratchscratchscratch.cpp : fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:ddvctoolscompilerutcsrcp2main.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
到底是什么导致了这种情况。
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 编译器错误:destuctor 的更宽松的抛出说明符
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- C++ G++ 编译器 - 错误:隐式声明的定义
- 这个失败的测试是将零添加到空指针未定义的行为、编译器错误还是其他什么?
- 模板模板参数和模板别名:编译器错误?
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- C1001内部编译器错误是由于矢量初始化(如数组)引起的
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 如何在C++中克服此 C4430 编译器错误?
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何在类模板的成员函数中正确调用函数对象?正在生成 Visual Studio 编译器错误 C2440
- C++自定义分配器大小参数作为模板参数会引发编译器错误