gpt4 book ai didi

c++ - 分配抽象类类型的对象

转载 作者:太空狗 更新时间:2023-10-29 20:04:34 26 4
gpt4 key购买 nike

我正在尝试将 CCTable View 合并到我的 cocos2d-x 应用程序中。我已经按照 testcpp 的源代码进行操作,但我仍然收到此错误并且不是 100% 确定原因

“分配抽象类类型‘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

游戏列表.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;
}

任何帮助将不胜感激

谢谢

最佳答案

您正在继承或说使用 CCtableViewDataSource 和 CCTableViewDelegate 类,因此您必须定义它的所有虚拟方法像下面这样:

# 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);

关于c++ - 分配抽象类类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18885191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com