我试图从另一个类中调用另一个方法内的方法,但是它给了我错误"变量牌不是类型名称"。我不确定这意味着什么。这是我的代码:
Cardstub.cpp
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <iostream>
#include "CardList.h";
#include "CardStub.h";
#define Ace 1
#define Jack 11
#define Queen 12
#define King 13
enum Suit { hearts, diamonds, clubs, spades };
void cardlist1(vector<Card1>);
void storeCard() {
int i = 0;
std::vector<Card1> deck(52);
std::vector<Card1> cardlist(52);
int temp;
for (Suit suit = hearts; suit <= spades; suit = Suit(suit + 1))
{
for (int rank = Ace; rank <= King; rank = rank++)
{
deck[i].suit = suit;
deck[i].rank = rank;
i++;
}
}
Card1 * CardList::addToTop(deck); //error is here
}
int main() {
storeCard();
system("pause");
return 0;
}
CardList.cpp
#include "CardList.h"
#include "CardStub.h"
#include <stdio.h>
void CardList::writeFile(FILE* File) {
}
void CardList::readFile(FILE *File) {
}
Card1 *CardList::addToTop(vector<Card1> deck) {
std::vector<Card1> cardlist(52);
cardlist = deck;
for (int count = 0; count <cardlist.size(); count++)
//For Loop to Display All Products
{
//cout << cardlist[count].rank << "\n" << cardlist[count].suit;
}
for (int i = 0; i < cardlist.size(); i++) {
if (cardlist[i].rank == 2)
cout << "Two ";
else if (cardlist[i].rank == 3)
cout << "Three ";
else if (cardlist[i].rank == 4)
cout << "Four ";
else if (cardlist[i].rank == 5)
cout << "Five ";
else if (cardlist[i].rank == 6)
cout << "Six ";
else if (cardlist[i].rank == 7)
cout << "Seven ";
else if (cardlist[i].rank == 8)
cout << "Eight ";
else if (cardlist[i].rank == 9)
cout << "Nine ";
else if (cardlist[i].rank == 10)
cout << "Ten ";
else if (cardlist[i].rank == 11)
cout << "Jack ";
else if (cardlist[i].rank == 12)
cout << "Queen ";
else if (cardlist[i].rank == 13)
cout << "King ";
else if (cardlist[i].rank == 1)
cout << "Ace ";
cout << "of ";
if (cardlist[i].suit == clubs)
cout << "Clubs\n";
else if (cardlist[i].suit == diamonds)
cout << "Diamonds\n";
else if (cardlist[i].suit == hearts)
cout << "Hearts\n";
else if (cardlist[i].suit == spades)
cout << "Spades\n";
}
}
/*
ICard* CardList::remove(int index) {
}
ICard* CardList::removeFromTop() {
}*/
CardStub.h
#include <stdio.h>
#define Ace 1
#define Jack 11
#define Queen 12
#define King 13
using namespace std;
struct Card1
{
Card1() {};
int rank;
Suit suit;
Card1(Suit s, int rank) {};
};
#endif
CardList.h
#if !defined(CARDLIST_H)
#define CARDLIST_H
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include "CardStub.h"
class CardList {
public:
virtual void writeFile(FILE *File) = 0;
virtual void readFile(FILE *File) = 0;
virtual Card1 * addToTop(vector<Card1> ) = 0;
//virtual ICard* remove(int index) = 0;
//virtual ICard* removeFromTop() = 0;
//public:
//virtual void removeCard(ICard*) = 0;
//virtual void add(ICard*) = 0;
};
#endif
错误发生在CardStub.cpp中,为什么会出现此错误?
答案 0 :(得分:1)
您在该行中缺少变量名称,因此它看起来像是函数声明而不是函数调用。期望deck
成为参数的类型。
你也有其他问题,要注意别人留下的评论。