C ++ Error3867:关于std :: forward_list成员引用错误

时间:2014-06-06 17:57:48

标签: c++

对于学校我们必须在c ++中创建游戏垄断,但我在我的甲板上遇到了问题。

我想使用std :: forward_list模板将我的cardpointers存储在其中但是有一些我无法解决的问题。

错误:

error C3867: 'std::forward_list<Card *,std::allocator<_Ty>>::pop_front': function call missing argument list; use '&std::forward_list<Card *,std::allocator<_Ty>>::pop_front' to create a pointer to member
line 65 column 1

error C3867: 'std::forward_list<Card *,std::allocator<_Ty>>::end': function call missing argument list; use '&std::forward_list<Card *,std::allocator<_Ty>>::end' to create a pointer to member
line 69 column 1

error C3867: 'std::forward_list<Card *,std::allocator<_Ty>>::pop_front': function call missing argument list; use '&std::forward_list<Card *,std::allocator<_Ty>>::pop_front' to create a pointer to member
line 70 column 1

error C3867: 'std::forward_list<Card *,std::allocator<_Ty>>::pop_front': function call missing argument list; use '&std::forward_list<Card *,std::allocator<_Ty>>::pop_front' to create a pointer to member
line 78 column 1


error C3867: 'std::forward_list<Card *,std::allocator<_Ty>>::end': function call missing argument list; use '&std::forward_list<Card *,std::allocator<_Ty>>::end' to create a pointer to member
line 84 column 1

我的甲板标题

#ifndef DECK
#define DECK

#include "CardType.h"
#include "player.h"
#include "Card.h"
#include <forward_list>

class Deck
{
public:
    Deck(CardType type); //community or chance
    Card* takeFront(); //take the front card of the deck
    void placeBack(Card* card); //place card back behind the deck
    void shuffle(); //pseudo-shuffle
private:
    CardType m_type;
    std::forward_list<Card*> m_deck;
};

#endif

最后我的cpp代码本身 (我在有错误的行中添加了额外的注释)

#include"Deck.h"
#include "BirthdayCard.h"
#include "AbsMoneyCard.h"
#include "AbsMoveCard.h"
#include "RelMoneyCard.h"
#include "RelMoveCard.h"
#include "ToJailCard.h"
#include "OutOfJailCard.h"
#include "GoBackCard.h"
#include "PayOrChanceCard.h"


Deck::Deck(CardType type)
{
    if (type == chance)
    {
        m_deck.emplace_front(new AbsMoveCard(chance, "Advance to Mayfair", 39));
        m_deck.emplace_front(new AbsMoveCard(chance, "Advance to Go", 0));
        m_deck.emplace_front(new AbsMoveCard(chance, "Avance to Trafalgar Square If you Pass 'Go' Collect $200", 24));
        m_deck.emplace_front(new AbsMoveCard(chance, "take a Trip to Marylebone Station and if you Pass 'Go' Collect $200", 15));
        m_deck.emplace_front(new AbsMoveCard(chance, "Advance to Pall Mall If you Pass 'Go' Collect $200", 11));
        m_deck.emplace_front(new RelMoneyCard(chance, "You are Assessed for Street Repairs $40 per House $115 per Hotel", 40, 115));
        m_deck.emplace_front(new RelMoneyCard(chance, "Make General Repairs on all of Your Houses. For each House pay $25. For each Hotel pay $100", 25, 100));
        m_deck.emplace_front(new AbsMoneyCard(chance, "Bank pays you dividend of $50", 50));
        m_deck.emplace_front(new AbsMoneyCard(chance, "Pay School Fees of $150.", 150));
        m_deck.emplace_front(new AbsMoneyCard(chance, "Speeding Fine $15", -15));
        m_deck.emplace_front(new AbsMoneyCard(chance, "You have won a Crossword Competition Collect $100", 100));
        m_deck.emplace_front(new AbsMoneyCard(chance, "Your Building and Loan Matures Collect $150", 150));
        m_deck.emplace_front(new AbsMoneyCard(chance, "'Drunk in Charge' Fine $20", -20));
        m_deck.emplace_front(new ToJailCard(chance, "Go to Jail.Move Directly to Jail. Do not pass 'Go' Do not Collect $200."));
        m_deck.emplace_front(new RelMoveCard(chance, "Go back 3 Spaces", -3));
        m_deck.emplace_front(new OutOfJailCard(chance, "Get out of Jail Free"));
    }
    else
    {
        m_deck.emplace_front(new AbsMoneyCard(community, "Income Tax refund Collect $20", 20));
        m_deck.emplace_front(new AbsMoneyCard(community, "From Sale of Stock you get $50", 50));
        m_deck.emplace_front(new AbsMoneyCard(community, "Pay Hospital $100", -100));
        m_deck.emplace_front(new AbsMoneyCard(community, "Receive Interest on 7 % Preference Shares $25", 25));
        m_deck.emplace_front(new AbsMoneyCard(community, "You have Won Second Prize in a Beauty Contest Collect $10", 10));
        m_deck.emplace_front(new AbsMoneyCard(community, "Bank Error in your Favour Collect $200", 200));
        m_deck.emplace_front(new AbsMoneyCard(community, "Annuity Matures Collect $100", 100));
        m_deck.emplace_front(new AbsMoneyCard(community, "You Inherit $100", 100));
        m_deck.emplace_front(new AbsMoneyCard(community, "Doctor's Fee Pay $50", -50));
        m_deck.emplace_front(new AbsMoneyCard(community, "Pay your Insurance Premium $50", -50));
        m_deck.emplace_front(new BirthdayCard(community, "It is YourBirthday Collect $10 from each Player", 10));
        m_deck.emplace_front(new OutOfJailCard(community, "Get out of Jail Free"));
        m_deck.emplace_front(new AbsMoveCard(community, "Advance to 'Go'", 0));
        m_deck.emplace_front(new ToJailCard(community, "Go to Jail.Move Directly to Jail. Do not Pass 'Go'. Do not Collect $200"));
        m_deck.emplace_front(new GoBackCard(community, "Go Back to Old Kent Road", 1));
        m_deck.emplace_front(new PayOrChanceCard(community, "Pay a $10 Fine or Take a 'Chance'", 10));
    }
}

void Deck::shuffle()
{
    std::forward_list<Card*> help;
    help.swap(m_deck);

    while (!help.empty())
    {
        if (rand() % 2 == 0)
        {
            m_deck.emplace_front(help.front());
            help.pop_front; //###line 65###
        }
        else
        {
            m_deck.emplace_after(m_deck.end ,help.front()); //###line 69###
            help.pop_front; //###line 70###
        }
    }
}

Card* Deck::takeFront()
{
    Card* help = m_deck.front();
    m_deck.pop_front; //###line 78###
    return help;
}

void Deck::placeBack(Card* card)
{
    m_deck.emplace_after(m_deck.end, card); //###line 84###
}

如果你能解决我的问题,那将是非常好的

1 个答案:

答案 0 :(得分:2)

你在函数调用中缺少一些():

void Deck::shuffle()
{
    std::forward_list<Card*> help;
    help.swap(m_deck);

    while (!help.empty())
    {
        if (rand() % 2 == 0)
        {
            m_deck.emplace_front(help.front());
            help.pop_front(); //###line 65###
        }
        else
        {
            m_deck.emplace_after(m_deck.end(), help.front()); //###line 69###
            help.pop_front(); //###line 70###
        }
    }
}

Card* Deck::takeFront()
{
    Card* help = m_deck.front();
    m_deck.pop_front(); //###line 78###
    return help;
}

void Deck::placeBack(Card* card)
{
    m_deck.emplace_after(m_deck.end(), card); //###line 84###
}