Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Syntax error with identifiers  (Read 1570 times)

0 Members and 1 Guest are viewing this topic.

Blingu

  • Newbie
  • *
  • Posts: 15
    • View Profile
Syntax error with identifiers
« on: September 16, 2018, 11:51:23 am »
Hi, I'm struggling with a compile-time error that tells me there's a syntax error with an identifier. It doesn't only appear with 'Ball', but also with other identifiers. I restarted my PC and VS already, but it still doesn't work. I'm already trying to fix it for a week.

//Blocks.h

#pragma once
#include <SFML/Graphics.hpp>
#include "Ball.h"
#include "Variables.h"

class Blocks
{
private:
        sf::RectangleShape blocks[16];
public:
        Blocks();
        sf::RectangleShape getShape(int i);
        bool checkCollision(Ball &ball);        // syntax error: identifier 'Ball'
        void draw(sf::RenderWindow &window);
};


//////////////////////////////////////////////////////////////

//Function checkCollision in Blocks.cpp

bool Blocks::checkCollision(Ball &ball)
{
        for (int i = 0; i < 16; i++)
        {
                if (ball.getShape().getGlobalBounds().intersects(blocks[i].getGlobalBounds()))
                {
                        blocks[i].setPosition(-100.f, -100.f);
                        return true;
                }
        }
        return false;
}

//////////////////////////////////////////////////////////////
//Function call in Game.cpp

if (blocks->checkCollision(*ball))       // 'Blocks::checkCollision': function does not take 1 arguments
{
        ball->moveAfterCollision();
}
 

There's no error with the definition of checkCollision(*ball) in Blocks.cpp, only with the declaration in Blocks.h.
ball->moveAfterCollision(); doesn't cause the problem too.
« Last Edit: September 16, 2018, 11:53:11 am by Blingu »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Syntax error with identifiers
« Reply #1 on: September 16, 2018, 04:04:58 pm »
Does Ball.h also include Blocks.h ? In which case you have a circular dependency. You can fix this with a Forward Declaration of Ball in Blocks.h

https://stackoverflow.com/a/4757718/6740859

Blingu

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Syntax error with identifiers
« Reply #2 on: September 16, 2018, 06:38:10 pm »
Thanks, I fixed it with a forward declaration. Can it be solved without it though? Just being curious.