#ifndef SPRITE_H
#define SPRITE_H
#include "drawEngine.h"
enum
{
SPRITE_CLASSID,
};
struct vector
{
float x;
float y;
};
class Sprite
{
public:
Sprite(DrawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);
~Sprite();
vector getPosition(void);
float getX(void):
float getY(void);
virtual void addLives(int num = 1);
int getLives(void);
bool isAlive(void);
virtual bool move(float x, float y);
protected:
DrawEngine *drawArea;
vector pos;
int spriteIndex;
int numLives;
int classID;
vector facingDirection;
void draw(float x, float y);
void erase(float x, float y);
};
#endif
Errors, errors, and more errors
So I'm following this tutorial, and they compile just fine and my code is just fine, im using everything they are using but I'm getting 14 errors.
Errors:
------ Build started: Project: evilMonkeys, Configuration: Debug Win32 ------
Compiling...
sprite.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2062: type 'float' unexpected
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2238: unexpected token(s) preceding ';'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2063: 'Sprite::spriteIndex' : not a function
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2040: 'Sprite::spriteIndex' : 'int (DrawEngine *,int,float,float,int)' differs in levels of indirection from 'int'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(31) : error C2039: 'getX' : is not a member of 'Sprite'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(17) : see declaration of 'Sprite'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(33) : error C2065: 'pos' : undeclared identifier
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(33) : error C2228: left of '.x' must have class/struct/union type
type is ''unknown-type''
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(36) : error C2039: 'getY' : is not a member of 'Sprite'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(17) : see declaration of 'Sprite'
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(38) : error C2228: left of '.y' must have class/struct/union type
type is ''unknown-type''
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(38) : error C3861: 'pos': identifier not found, even with argument-dependent lookup
main.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2062: type 'float' unexpected
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2238: unexpected token(s) preceding ';'
game.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2062: type 'float' unexpected
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.h(24) : error C2238: unexpected token(s) preceding ';'
Generating Code...
Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\Debug\BuildLog.htm"
evilMonkeys - 14 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
Code:
enum
{
SPRITE_CLASSID, <-- remove this comma
};
Commas are for separating the items in an enumeration, but you only have one item so there is nothing to separate. That pretty much breaks all the code from that point on, so recompile and see which errors still remain.
Like I said my code is exactly the same as the guy's tutorial. Nothing is diffrent, his will compile my wont. Yes I removed the comma before I posted this and it didn't change anything. But it's saying "type 'float' unexpected"
vector getPosition(void);
float getX(void):
float getY(void); <------- This is not being identified like it's spitting out float because somewhere we didn't identify it?
virtual void addLives(int num = 1);
int getLives(void);
bool isAlive(void);
virtual bool move(float x, float y);
vector getPosition(void);
float getX(void):
float getY(void); <------- This is not being identified like it's spitting out float because somewhere we didn't identify it?
virtual void addLives(int num = 1);
int getLives(void);
bool isAlive(void);
virtual bool move(float x, float y);
In C++ statements and declarations should end with a semicolon, so...
float getX(void): <-- Here's your problem
float getY(void);
On a further note, usage of the 'void' keyword to indicate an empty parameterlist isn't really necessary. You might as well write:
float getX();
float getY();
float getX(void): <-- Here's your problem
float getY(void);
On a further note, usage of the 'void' keyword to indicate an empty parameterlist isn't really necessary. You might as well write:
float getX();
float getY();
Grrr. Yes another simple simple simple and very very simple typo. And I read over that code a zillion times. But I still have the other errors I was concerned about which are still on there that weren't answered due to my lack of code but here it is:
Errors:
------ Build started: Project: evilMonkeys, Configuration: Debug Win32 ------
Compiling...
sprite.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2063: 'Sprite::spriteIndex' : not a function
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2040: 'Sprite::spriteIndex' : 'int (DrawEngine *,int,float,float,int)' differs in levels of indirection from 'int'
Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\Debug\BuildLog.htm"
evilMonkeys - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
Code:
Errors:
------ Build started: Project: evilMonkeys, Configuration: Debug Win32 ------
Compiling...
sprite.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2063: 'Sprite::spriteIndex' : not a function
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2040: 'Sprite::spriteIndex' : 'int (DrawEngine *,int,float,float,int)' differs in levels of indirection from 'int'
Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\Debug\BuildLog.htm"
evilMonkeys - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
Code:
#include "sprite.h"Sprite::spriteIndex(DrawEngine *de, int s_index, float x, float y, int i_lives){ drawArea = de; pos.x = x; pos.y = y; spriteIndex = s_index; numLives = i_lives; facingDirection.x = 1; facingDirection.y = 0; classID = SPRITE_CLASSID;}Sprite::~Sprite(){ //erase the dying sprite erase(pos.x, pos.y);}vector Sprite::getPosition(void){ return pos;}float Sprite::getX(void){ return pos.x;}float Sprite::getY(void){ return pos.y;}void Sprite::addLives(int num){ numLives += num;}int Sprite::getLives(void){ return numLives;} bool Sprite::isAlive(void){ return (numLives > 0); /* Dan's code if (numLives <= 0) return false; return true;*/}bool Sprite::move(float x, float y){ //erase sprite erase(pos.x, pos.y); pos.x += x; pos.y += y; facingDirection.x = x; facingDirection.y = y; // draw sprite draw(pos.x, pos.y); return true;}void Sprite::draw(float x, float y){ drawArea->drawSprite(spriteIndex,(int)x,(int)y);}void Sprite::erase(float x, float y){ drawArea->eraseSprite((int)x, (int)y);}
Quote:Original post by Ra
enum
{
SPRITE_CLASSID, <-- remove this comma
};
Commas are for separating the items in an enumeration, but you only have one item so there is nothing to separate. That pretty much breaks all the code from that point on, so recompile and see which errors still remain.
Actually a comma is perfectly valid here and makes it far easier to add items to the enum.
You have a member and a method called "spriteIndex". Rename one of the two and it should be find.
Additionally, I wouldn't call your vector struct "vector", because you'll very likely get conflicts with std::vector at some point.
Additionally, I wouldn't call your vector struct "vector", because you'll very likely get conflicts with std::vector at some point.
Quote:Original post by Roberts91
sprite.cpp
c:\Users\Administrator\Documents\Visual Studio Projects\evilMonkeys\sprite.cpp(4) : error C2063: 'Sprite::spriteIndex' : not a function
[...]
Sprite::spriteIndex(DrawEngine *de, int s_index, float x, float y, int i_lives)
{
drawArea = de;
pos.x = x;
pos.y = y;
spriteIndex = s_index;
numLives = i_lives;
facingDirection.x = 1;
facingDirection.y = 0;
classID = SPRITE_CLASSID;
}
Where's the return value for that function? It's lacking one. Hence it not looking like a function to the compiler.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement