Пытаюсь собрать кое-какую игру на телефон, но совершенно не знаю языка.
Помогите пожалуйста разобраться, насколько я понял ошибка синтаксическая.
Лог компилятора:
exl@exl-desktop /home/z6/cooldown-game-read-only $ make
arm-linux-gnueabi-g++ -o cooldown src/*.cpp `sdl-config --libs` -lm -lz -lpng -lSDL_image -lfreetype -lSDL_mixer -lSDL_ttf `sdl-config --cflags`
src/PlayGame.cpp: In constructor `PlayGame::PlayGame()':
src/PlayGame.cpp:45: warning: passing `double' for converting 2 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp:45: warning: passing `double' for converting 3 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp:53: warning: passing `double' for converting 2 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp:53: warning: passing `double' for converting 3 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp: In member function `bool PlayGame::moveCursorTo(int, int)':
src/PlayGame.cpp:226: warning: passing `double' for converting 1 of `void Sprite::centerTo(int, int)'
src/PlayGame.cpp:226: warning: passing `double' for converting 2 of `void Sprite::centerTo(int, int)'
src/PlayGame.cpp:227: warning: passing `double' for converting 1 of `void Sprite::centerTo(int, int)'
src/PlayGame.cpp:227: warning: passing `double' for converting 2 of `void Sprite::centerTo(int, int)'
src/PlayGame.cpp: In member function `void PlayGame::placeCurrent()':
src/PlayGame.cpp:281: warning: passing `double' for converting 2 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp:281: warning: passing `double' for converting 3 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp: In member function `void PlayGame::penalty()':
src/PlayGame.cpp:470: warning: converting to `int' from `float'
src/PlayGame.cpp: In member function `bool PlayGame::playLevel(Level*)':
src/PlayGame.cpp:560: warning: passing `double' for converting 2 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/PlayGame.cpp:560: warning: passing `double' for converting 3 of `static SDL_Surface* Sprite::ScaleSurface(SDL_Surface*, Uint16, Uint16)'
src/Queue.cpp: In member function `void Queue::update()':
src/Queue.cpp:50: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
src/Queue.cpp:51: error: no match for 'operator==' in 'it == std::list<_Tp, _Alloc>::rbegin() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
src/Queue.cpp: In member function `virtual void Queue::redraw()':
src/Queue.cpp:61: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
src/TileFactory.cpp: In static member function `static Tile* TileFactory::alter(Tile*, std::string)':
src/TileFactory.cpp:46: warning: converting to `int' from `double'
make: *** [build] Error 1
Queue.cpp:
#include <typeinfo>
#include"main.h"#include"Queue.h"#include"ResourceManager.h"#include"Logger.h"
Queue::Queue(Level *nlevel)
: Sprite(),
level(nlevel)
{
moveTo(PLAY_QUEUE_X, PLAY_QUEUE_Y);
setImage(ResourceManager::instance()->getImage("images/queue.png"));
for (int i=0; i<QUEUE_SIZE; ++i)
addNew()->moveTo(pos.x + width()/2 - tiles.front()->width()/2, pos.y + height() - (i+1) * tiles.front()->height());
}
bool Queue::isOK(Tile *t)
{
if (tiles.empty())
return true;
if (t->getType() == tiles.back()->getType())
return false;
return true;
}
Tile* Queue::addNew()
{
Tile* next = level->randomTile();
while (!isOK(next))
{
delete next;
next = level->randomTile();
}
tiles.push_back(next);
return next;
}
Queue::~Queue()
{
#ifndef NOLOG
Logger::log(EXTRADEBUG) << "~Queue";
#endif
for (list<Tile*>::const_iterator it = tiles.begin(); it != tiles.end(); ++it)
delete *it;
}
void Queue::update()
{
Sprite::update();
for (list<Tile*>::const_reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
if (it == tiles.rbegin())
(*it)->redraw();
else
(*it)->update();
return;
}
void Queue::redraw()
{
Sprite::redraw();
for (list<Tile*>::const_reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
(*it)->redraw();
}
Tile *Queue::shift()
{
if (tiles.empty())
return 0;
Tile *first = tiles.front();
tiles.pop_front();
addNew()->moveTo(tiles.front()->x(), pos.y+height() - 5*tiles.front()->height());
int i=0;
for (list<Tile*>::const_iterator it = tiles.begin(); it != tiles.end() && (*it)!=tiles.back(); ++it, ++i)
(*it)->animateTo(pos.x + width()/2 - (*it)->width()/2, pos.y + height() - (i+1) * (*it)->height(), QUEUESHIFTTIME);
first->animateTo(pos.x + width()/2 - first->width()/2, pos.y + height(), QUEUESHIFTTIME);
return first;
}
Queue.h:
#ifndef QUEUE_H
#define QUEUE_H
#include <list>
#include"Level.h"#include"Sprite.h"#include"Tile.h"using namespace std;
/**
* \class Queue
* \brief Waiting queue during gameplay
*/class Queue : public Sprite
{
public:
/**
* \brief Queue constructor
* \param nlevel Pointer to the Level where Queue will be used
*
* The Level is needed, because it knows allowed Tile types.
*/
Queue(Level *nlevel);
/// \brief Destructor
~Queue();
/**
* \brief Remove and return Tile at the bottom,
* shift queue (add a new one at the end)
*/
Tile *shift();
void update();
void redraw();
protected:
/**
* \brief Generates a random tile which is different from the last one and adds to queue
* \return New tile
*/
Tile* addNew();
/// \brief Returns TRUE if the tile can be added to the queue (to avoid repetitions)bool isOK(Tile* t);
list<Tile*> tiles; ///< List of Tiles in the queue
Level *level; ///< Level where this Queue is used
};
#endif
Здравствуйте, EXL, Вы писали:
EXL>Пытаюсь собрать кое-какую игру на телефон, но совершенно не знаю языка. EXL>Помогите пожалуйста разобраться, насколько я понял ошибка синтаксическая. EXL>Лог компилятора:
EXL>
..
EXL>src/Queue.cpp: In member function `void Queue::update()':
EXL>src/Queue.cpp:50: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
EXL>src/Queue.cpp:51: error: no match for 'operator==' in 'it == std::list<_Tp, _Alloc>::rbegin() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
EXL>src/Queue.cpp: In member function `virtual void Queue::redraw()':
EXL>src/Queue.cpp:61: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
..
EXL>
Пишет, что не может сравнить const_reverse_iterator с reverse_iterator. Это очень странно.
(Все разумные реализации STL должны уметь.)
Попробуй так:
EXL>Queue.cpp:
..
void Queue::update()
{
Sprite::update();
for (list<Tile*>::reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
if (it == tiles.rbegin())
(*it)->redraw();
else
(*it)->update();
return;
}
void Queue::redraw()
{
Sprite::redraw();
for (list<Tile*>::reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
(*it)->redraw();
}
..
Здравствуйте, Chorkov, Вы писали:
C>Здравствуйте, EXL, Вы писали:
EXL>>Пытаюсь собрать кое-какую игру на телефон, но совершенно не знаю языка. EXL>>Помогите пожалуйста разобраться, насколько я понял ошибка синтаксическая. EXL>>Лог компилятора:
EXL>>
C>..
EXL>>src/Queue.cpp: In member function `void Queue::update()':
EXL>>src/Queue.cpp:50: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
EXL>>src/Queue.cpp:51: error: no match for 'operator==' in 'it == std::list<_Tp, _Alloc>::rbegin() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
EXL>>src/Queue.cpp: In member function `virtual void Queue::redraw()':
EXL>>src/Queue.cpp:61: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, _Alloc = std::allocator<Tile*>]()'
C>..
EXL>>
C>Пишет, что не может сравнить const_reverse_iterator с reverse_iterator. Это очень странно. C>(Все разумные реализации STL должны уметь.) C>Попробуй так:
EXL>>Queue.cpp: C>
C>..
C>void Queue::update()
C>{
C> Sprite::update();
C> for (list<Tile*>::reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
C> if (it == tiles.rbegin())
C> (*it)->redraw();
C> else
C> (*it)->update();
C> return;
C>}
C>void Queue::redraw()
C>{
C> Sprite::redraw();
C> for (list<Tile*>::reverse_iterator it = tiles.rbegin(); it != tiles.rend(); ++it)
C> (*it)->redraw();
C>}
C>..
C>
EXL>src/Queue.cpp:50: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*, EXL>src/Queue.cpp:51: error: no match for 'operator==' in 'it == std::list<_Tp, _Alloc>::rbegin() [with _Tp = Tile*
EXL>src/Queue.cpp:61: error: no match for 'operator!=' in 'it != std::list<_Tp, _Alloc>::rend() [with _Tp = Tile*,
EXL>
Это баг текущего стандарта С++: reverse_iterator и const_reverse_iterator не сравниваются.
Воркэраунд:
EXL>void Queue::redraw()
EXL>{
EXL> Sprite::redraw();
EXL> for (list<Tile*>::const_reverse_iterator it = tiles.rbegin(), rend = tiles.rend(); it != rend; ++it)
EXL> (*it)->redraw();
EXL>}
EXL>
(в остальных местах -- аналогично).
PS. В таких случаях лучше указывать номера важных строк в запощенном коде. А то приходится искать/гадать. Неудобно.
Ага, в предыдущем варианте не обновляется экран.
А в Вашем — компилятор ругается на строку
if (it == tiles.rbegin())
В фрагменте кода
void Queue::update()
{
Sprite::update();
for (list<Tile*>::const_reverse_iterator it = tiles.rbegin(), rend = tiles.rend(); it != rend; ++it)
if (it == tiles.rbegin())
(*it)->redraw();
else
(*it)->update();
return;
}
void Queue::redraw()
{
Sprite::redraw();
for (list<Tile*>::const_reverse_iterator it = tiles.rbegin(), rend = tiles.rend(); it != rend; ++it)
(*it)->redraw();
}
Здравствуйте, EXL, Вы писали:
EXL>Здравствуйте, quodum, Вы писали:
EXL>Ага, в предыдущем варианте не обновляется экран. EXL>А в Вашем — компилятор ругается на строку
EXL>
EXL>if (it == tiles.rbegin())
EXL>
EXL>В фрагменте кода
EXL>
EXL>//...
EXL>
эта строка там по ошибке дизайна...
void Queue::update()
{
Sprite::update();
if (!tiles.empty)
{
list<Tile*>::const_reverse_iterator it = tiles.rbegin(), rend = tiles.rend();
(*it)->redraw();
for (++it ; it != rend; ++it) (*it)->update();
}
}