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

Author Topic: [SOLVED]Error with SFML game development book  (Read 2814 times)

0 Members and 1 Guest are viewing this topic.

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
[SOLVED]Error with SFML game development book
« on: February 02, 2015, 07:33:50 pm »
So at the end of chapter 4 i get this error when trying to compile. It is in command.hpp that the error is being reported, but it is being called in player.cpp.

Command.hpp
#ifndef COMMAND_HPP
#define COMMAND_HPP

#include "Category.hpp"

#include <SFML/System/Time.hpp>

#include <functional>
#include <cassert>



class SceneNode;

struct Command
{
                                                                                                Command();

        std::function<void(SceneNode&, sf::Time)>       action;
        unsigned int                                                            category;
};

template <typename GameObject, typename Function>
std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
{
        return [=] (SceneNode& node, sf::Time dt)
        {
                // Check if cast is safe
                assert(dynamic_cast<GameObject*>(&node) != nullptr);

                // Downcast node and invoke function on it
                fn(static_cast<GameObject&>(node), dt);
        };
}
#endif // COMMAND_HPP

 

Command.cpp:

#include "Command.hpp"


Command::Command()
: action()
, category(Category::None)
{
}

 

Where it is linking in player.cpp
void Player::initializeActions()
{
        const float playerSpeed = 200.f;

        mActionBinding[MoveLeft].action  = derivedAction<Aircraft>(AircraftMover(-playerSpeed, 0.f));
        mActionBinding[MoveRight].action = derivedAction<Aircraft>(AircraftMover(+playerSpeed, 0.f));
        mActionBinding[MoveUp].action    = derivedAction<Aircraft>(AircraftMover(0.f, -playerSpeed));
        mActionBinding[MoveDown].action  = derivedAction<Aircraft>(AircraftMover(0.f, +playerSpeed));
}
 


Source Code for the book:
https://github.com/SFML/SFML-Game-Development-Book

This is from chapter 4


The exact error is:
Command.hpp:32: error: type 'const AircraftMover' does not provide a call operator
                fn(static_cast<GameObject&>(node), dt);
                ^
« Last Edit: February 03, 2015, 05:39:14 pm by devilswin »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Error with SFML game development book
« Reply #1 on: February 03, 2015, 01:03:14 am »
This is just a guess based on your error message, but did you remember to make a call operator function in AircraftMover? If so, did you remember to make it const?

void operator() (Aircraft& aircraft, sf::Time) const



devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Error with SFML game development book
« Reply #2 on: February 03, 2015, 02:30:59 pm »
Can you explain in a bit more detail, i have literally just followed the source code + book so i don't know where it could be wrong.

Sorry if this answer/question appeared rude

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Error with SFML game development book
« Reply #3 on: February 03, 2015, 04:54:03 pm »
I actually haven't ever read the book myself. I just followed the link in your first post and looked at some of the source files for chapter 4. I'm referring to line 18 in this Player.cpp:
https://github.com/SFML/SFML-Game-Development-Book/blob/master/04_Input/Source/Player.cpp

I was just thinking that if you typed the example source code manually into your own files you might have missed that. Though if you just copied and pasted the whole thing without modification then your problem might be elsewhere. Maybe someone who has read through the book will be able to help further.

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: Error with SFML game development book
« Reply #4 on: February 03, 2015, 05:16:18 pm »
Ah, ok yeah, i manually retyped everything just to understand the code better

Now i get a 2 duplicate symbols error with regards to category.o and command.o
« Last Edit: February 03, 2015, 05:24:05 pm by devilswin »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Error with SFML game development book
« Reply #5 on: February 03, 2015, 06:57:08 pm »
Now i get a 2 duplicate symbols error with regards to category.o and command.o

This error means that you have something with the same name in two places. It is hard to say exactly what is causing that problem for you, but one of the ways this can happen is if you include the same header file twice. Make sure all of your header files have unique include guards so that they don't get included more than once. The book shows examples of this:
Code: [Select]
#ifndef UNIQUE_NAME_HPP
#define UNIQUE_NAME_HPP

// ...The rest of the header file

#endif

Also just make sure you didn't give 2 functions, classes, or variables the same name. Look through your code for any typos.

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: [SOLVED]Error with SFML game development book
« Reply #6 on: February 04, 2015, 03:37:07 pm »
It was weird, the solution i found was to clean and rebuild the thing...idk if there is something i missed