Search code examples
c++uitableviewcocos2d-x

allocating an object of abstract class type


im trying to incorporate a CCTable view in my cocos2d-x app. i have followed the source code from the testcpp and i am still getting this error and in not 100% sure why

"allocating an object of abstract class type 'GameList'"

here is my source code

GameList.h

#ifndef __Squares__GameList__
#define __Squares__GameList__

#include "cocos2d.h"
#include "cocos-ext.h"
#include "GameListScene.h"
#include "GameManager.h"

using namespace cocos2d;

class GameList : public CCLayer, public extension::CCTableViewDataSource, public extension::CCTableViewDelegate

{
public:
    virtual bool init();
    CREATE_FUNC(GameList);

    ~GameList(void);

    CCLabelTTF* titleLabel;
    CCLabelTTF* loginLabel;
    CCLabelTTF* passwordLabel;

    virtual void tableCellTouched(extension::CCTableView* table, extension::CCTableViewCell* cell);
    virtual CCSize tableCellSizeForIndex(extension::CCTableView *table, unsigned int idx);
    virtual unsigned int numberOfCellsInTableView(extension::CCTableView *table);
};

#endif

GameList.cpp

USING_NS_CC;
USING_NS_CC_EXT;

bool GameList::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }

    CCSize size = CCDirector::sharedDirector()->getWinSize();

    CCTableView* tableView = CCTableView::create(this, CCSizeMake(250, 60));
    tableView->setDirection(kCCScrollViewDirectionHorizontal);
    tableView->setPosition(ccp(20,size.height/2-30));
    tableView->setDelegate(this);
    this->addChild(tableView);
    tableView->reloadData();

    return true;
}

GameList::~GameList(void)
{

}

void GameList::tableCellTouched(CCTableView* table, CCTableViewCell* cell)
{
    CCLOG("cell touched at index: %i", cell->getIdx());
}

CCSize GameList::tableCellSizeForIndex(CCTableView *table, unsigned int idx)
{
    return CCSizeMake(60, 60);
}

unsigned int GameList::numberOfCellsInTableView(CCTableView *table)
{
    return 20;
}

any help would be appreciated

Thanks


Solution

  • You are inheriting or say using CCtableViewDataSource & CCTableViewDelegate Classes so u must define it's all virtual methods like following :

    # CCTableViewDataSource
    
    virtual CCSize cellSizeForTable(CCTableView *table);
    
    virtual  CCTableViewCell* tableCellAtIndex(CCTableView *table, unsigned int idx);
    
    virtual unsigned int numberOfCellsInTableView(CCTableView *table);
    
    virtual bool hasFixedCellSize();
    
    virtual CCSize cellSizeForIndex(CCTableView *table, unsigned int idx);
    
    # CCTableViewDelegate
    
    virtual void tableCellTouched(CCTableView* table,CCTableViewCell* cell);