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-BookThis 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);
^