其中一些:
在函数’int main(int,char **)’中:
[Error] no matching function for call to 'deckOfCards::shuffle(deckOfCards&)'[Note] candIDate is:In file included from main.cpp[Note] voID deckOfCards::shuffle(std::vector<Card>&)[Note] no kNown conversion for argument 1 from 'deckOfCards' to 'std::vector<Card>&'[Error] 'dealCard' was not declared in this scope
#include <iostream> using namespace std; class Card { private: int m_suit; int m_face; public: Card(int face,int suit); static string suits[]; static string faces[]; string toString(string s_face,string s_suit); int getFace(); voID setFace(int face); int getSuit(); voID setSuit(int suit); }; Card::Card(int face,int suit) { m_face = face; m_suit = suit; } string Card::suits[] = {"Hearts","Diamonds","Clubs","Spades"}; string Card::faces[] = {"Ace","Deuce","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; int Card::getFace(){return m_face;} voID Card::setFace(int face){m_face = face;} int Card::getSuit(){return m_suit;} voID Card::setSuit(int suit){m_suit = suit;} string Card::toString(string s_face,string s_suit) { string card = s_face + " of " + s_suit; return card; } #include <iostream> // cout#include <algorithm> // random_shuffle#include <vector> // vector#include <ctime> // time#include <cstdlib> #include "Card.h"using namespace std;class deckOfCards{ private: vector<Card> deck; public: deckOfCards(); static int count; static int next; voID shuffle(vector<Card>& deck); Card dealCard(); bool moreCards();};int deckOfCards::count = 0;int deckOfCards::next = 0;deckOfCards::deckOfCards(){ const int FACES = 12; const int SUITS = 4; int currentCard = 0; for (int face = 0; face < FACES; face++) { for (int suit = 0; suit < SUITS; suit++) { Card card = Card(face,suit); //card created and initialized deck.push_back(card); currentCard++; } }}voID deckOfCards::shuffle(vector<Card>& deck){ random_shuffle(deck.begin(),deck.end()); /*vector<Card>::iterator iter; for (iter = deck.begin(); iter!=deck.end(); iter++) { Card currentCard = *iter; random_shuffle(deck.begin(),deck.end()); Card randomCard = deck[num]; //change values..... }*/}Card deckOfCards::dealCard(){ Card nextCard = deck[next]; next++; return nextCard;}bool deckOfCards::moreCards(){ if (count < 52) { count++; return true; } else return false;} #include <iostream>#include "deckOfCards.h"using namespace std;int main(int argc,char** argv) { deckOfCards cardDeck; // create DeckOfCards object cardDeck.shuffle(cardDeck); // shuffle the cards in the deck while (cardDeck.moreCards() == true) { cout << dealCard(cardDeck);// deal the cards in the deck } return 0;}解决方法 您正尝试使用deckOfCards参数调用DeckOfCards :: shuffle:
deckOfCards cardDeck; // create DeckOfCards objectcardDeck.shuffle(cardDeck); // shuffle the cards in the deck
但该方法采用向量< Card>&:
voID deckOfCards::shuffle(vector<Card>& deck)
编译器错误消息非常清楚.我会在编译器与你谈话时解释它.
错误:
[Error] no matching function for call to 'deckOfCards::shuffle(deckOfCards&)'
转述:
hey,pal. You’re trying to call a function called
shuffle
which
apparently takes a single parameter of type
reference-to-deckOfCards
,but there is no such function.
错误:
[Note] candIDate is:In file included from main.cpp[Note] voID deckOfCards::shuffle(std::vector&)
转述:
I mean,maybe you meant this other function called
shuffle
,but that
one takes a reference-tovector<something>
.
错误:
[Note] no kNown conversion for argument 1 from 'deckOfCards' to 'std::vector&'
总结Which I’d be happy to call if I knew how to convert from a
deckOfCards
to avector
; but I don’t. So I won’t.
以上是内存溢出为你收集整理的C [错误]没有匹配的呼叫功能全部内容,希望文章能够帮你解决C [错误]没有匹配的呼叫功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)