Reputation: 1
struct Ball {
SDL_Surface *picture;
SDL_Rect des;
SDL_Rect source;
int speedX;
int speedY;
};
class Block {
public:
SDL_Surface *color;
SDL_Rect des;
SDL_Rect source;
bool activation;
bool invisibility;
bool checkHit (Ball *ball);
void makeInvisible();
};
bool Block::checkHit(Ball *ball)
{
if (activation)
{
if (ball->des.x >= Block.des.x && ball->des.x <= Block.des.x + Block.source.w)
{
ball->speedY *= -1;
activation = false;
return true;
}
else return false;
}
}
When I want to compile this program , compiler finds an error at Block::checkHit error C2275: 'Block' : illegal use of this type as an expression
What can I do ?
Upvotes: 0
Views: 106
Reputation: 18358
You're using class name as prefix in your expression. This is invalid syntax, inside the class you don't need prefix to access the members. Replace expressions such as Block.des.x
with des.x
.
Upvotes: 1
Reputation: 672
If you want to access Block's own member variables, just remove the Block.
parts and you should be ok.
If you want to be absolutely explicit, you could alternatively use use this->des.x
instead of plain des.x
.
Upvotes: 2