都是inline惹的禍

1.文件yoffgroup.h函數

class YOffGroup
{
public:
    YOffGroup(short roomId);
    ~YOffGroup();
    inline bool setOffGamerWithSeat(char seat, YGamer*gamer);
private:
    YGamer *m_offGamers[3]; /**< 存放替代玩家遊戲的AI, 下標就是座位號*/
    short m_roomId;      /**< 該組所對應的房間id */

};spa

2.源文件  yoffgroup.cpp遊戲

bool YOffGroup::setOffGamerWithSeat(char seat, YGamer *gamer){
    if(seat<0|| seat >2)
    {
        return false;
    }
    YGamer *old = m_offGamers[seat];
    //            delete m_offGamers[seat];
    delete old;
    m_offGamers[seat] = gamer;
    return true;
}it


3,以上將標註的有inline的函數的實現放在了源文件,在調用時就會出這樣的莫名錯誤io

error: undefined reference to `YOffGroup::setOffGamerWithSeat(char, YGamer*)'class

4,對於以上的錯誤有兩個解決方案error

a,將inline去掉文件

b,將原文件中對應的實現放到頭文件中
解決方案

相關文章
相關標籤/搜索