dimanche 29 juillet 2018

'std::shared_ptr' has not been declared , #include

I know there are a lot of similar questions around, but most of them solve the problem including memory. I had this issue before and that solution seemed to have fixed the problem last time, but not this one.

I am working on a university project with a mate who uses a macbook, i use Windows 10 but usually is not a problem. We are working with Clion and Cmake and we use SFML library.

At this time, the project works very well on her macbook but it is not running on mine. The code is the same, the directories are the same and in the same locations. Last time i had this problem and i solved, as i was saying, including in our ResourceHolder.h file. Now I can't include that file in our Character.h file (Don't know why, it's like they can't find eachother, but the Cmakelist.txt contains all our files). I tried by moving through our files-tree of course, but nothing worked. If i include memory in Character.h the project run until 96% then a lot of undefined reference errors show up.

Can someone help me or explaining me how to solve for once this problem with shared pointers? I'd like to know why i can't include that file (ResourceHolder) in another file of the same project, too.

This is the Cmake file: cmake_minimum_required(VERSION 3.8) project(BlackRose)

cmake_policy(SET CMP0074 OLD)
set(SFML_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/SFML)

set(CMAKE_CXX_STANDARD 11)

message("Adding test subdir")
add_subdirectory(test)


set(SOURCE_FILES source/Game.cpp include/Game.h 
include/management/ResourceHolder.h source/ProceduralMap.cpp 
include/ProceduralMap.h
    include/management/ResourceIdentifier.h source/World.cpp include/World.h 
    source/Characters/Character.cpp include/Characters/Character.h
    include/Inventory.h source/Characters/PlayerCharacter.cpp 
    include/Characters/PlayerCharacter.h source/Objects/Weapon.cpp
    include/Objects/Weapon.h source/Objects/Shield.cpp i 
    include/Objects/Shield.h source/Characters/Enemy.cpp 
    include/Characters/Enemy.h
    source/Entity.cpp include/Entity.h source/Objects/Object.cpp 
    include/Objects/Object.h source/Objects/ConsumableObject.cpp
    include/Objects/ConsumableObject.h source/Objects/RangedWeapon.cpp 
    include/Objects/RangedWeapon.h source/Objects/MeleeWeapon.cpp
    include/Objects/MeleeWeapon.h source/Projectile.cpp include/Projectile.h 
    include/Random.h source/Random.cpp
    source/Objects/Tile.cpp include/Objects/Tile.h 
    source/Objects/Healpack.cpp include/Objects/Healpack.h 
    source/textDisplay.cpp include/textDisplay.h)
 add_executable(BlackRose source/main.cpp)


 set(CMAKE_MODULE_PATH ${SFML_ROOT}/sfml_cmake)
 find_package(SFML REQUIRED system window graphics network audio)
 include_directories(${SFML_INCLUDE_DIR})

 message("Add library")
 add_library(core ${SOURCE_FILES})
 target_link_libraries(BlackRose ${SFML_LIBRARIES} core)

 get_directory_property(output INCLUDE_DIRECTORIES)
 message("Include directories:" ${output})

This is the Header:

#ifndef BLACKROSE_CHARACTER_H
#define BLACKROSE_CHARACTER_H


#include <SFML/System.hpp> 
#include "../Inventory.h"
#include "../Objects/Weapon.h"
#include "../Objects/Shield.h"
#include "../Entity.h"
#include <memory>




class Character: public Entity {
public:
 Character();
 //virtual ~Character() = 0;
 virtual void move();
 virtual void fight();
 //basic interaction with the world, it will be associated with a key
 virtual bool interactWithObject(std::shared_ptr <Object> &object);
 virtual void die();
 void update();
 void display();

public:
 int hp;
 int hpMax;
 int attackDamage;

 bool barDisplayed = false;
 sf::RectangleShape bar;
 sf::RectangleShape lifeBar;

protected:
 int resistance;
 int speed;
 sf::Vector2f position;
 Inventory inventory;
 sf::Clock timerTextures;
};


#endif //BLACKROSE_CHARACTER_H

The .cpp file:

#include "../../include/Characters/Character.h"



Character::Character() {
  //all characters are this big
  rect.setSize(sf::Vector2f(32,32));

  //life bar
  bar = sf::RectangleShape(sf::Vector2f(32,5));
  lifeBar = sf::RectangleShape(sf::Vector2f(32,5));
  bar.setOutlineThickness(3);
  bar.setOutlineColor(sf::Color::Black);
  bar.setFillColor(sf::Color::Black);
  lifeBar.setFillColor(sf::Color::Green);
 /*
  bar.setPosition(position.x, position.y-16);
  lifeBar.setPosition(position.x, position.y-16);
*/


 //TODO istanzia un inventory
 }

 bool Character::interactWithObject(std::shared_ptr <Object> &object) {
 return true;
 }

 ...other methods

these are errors show up when I do not include memory:

In file included from C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:5:0: c:\users\ludovico\clionprojects\blackrose\include\characters\character.h:26:42: error: 'std::shared_ptr' has not been declared virtual bool interactWithObject(std::shared_ptr &object);

                                      ^

c:\users\ludovico\clionprojects\blackrose\include\characters\character.h:26:53: error: expected ',' or '...' before '<' token virtual bool interactWithObject(std::shared_ptr &object);

                                                 ^

C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:37:41: error: 'bool Character::interactWithObject' is not a static data member of 'class Character' bool Character::interactWithObject(std::shared_ptr &object) {

                                     ^

C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:37:36: error: 'shared_ptr' is not a member of 'std' bool Character::interactWithObject(std::shared_ptr &object) {

                                ^

C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:37:59: error: expected primary-expression before '>' token bool Character::interactWithObject(std::shared_ptr &object) {

                                                       ^

C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:37:62: error: 'object' was not declared in this scope bool Character::interactWithObject(std::shared_ptr &object) {

                                                          ^

C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\Character.cpp:37:70: error: expected ',' or ';' before '{' token bool Character::interactWithObject(std::shared_ptr &object) {

                                                                  ^

CMakeFiles\core.dir\build.make:104: recipe for target 'CMakeFiles/core.dir/source/Characters/Character.cpp.obj' failed mingw32-make.exe[2]: * [CMakeFiles/core.dir/source/Characters/Character.cpp.obj] Error 1 mingw32-make.exe[2]: Waiting for unfinished jobs.... In file included from c:\users\ludovico\clionprojects\blackrose\include\characters\playercharacter.h:9:0, from C:\Users\Ludovico\CLionProjects\BlackRose\source\Characters\PlayerCharacter.cpp:5: c:\users\ludovico\clionprojects\blackrose\include\characters\Character.h:26:42: error: 'std::shared_ptr' has not been declared virtual bool interactWithObject(std::shared_ptr &object); ^ c:\users\ludovico\clionprojects\blackrose\include\characters\Character.h:26:53: error: expected ',' or '...' before '<' token virtual bool interactWithObject(std::shared_ptr &object); ^ mingw32-make.exe[2]: [CMakeFiles/core.dir/source/Characters/PlayerCharacter.cpp.obj] Error 1 mingw32-make.exe[1]: * [CMakeFiles/core.dir/all] Error 2 CMakeFiles\core.dir\build.make:118: recipe for target 'CMakeFiles/core.dir/source/Characters/PlayerCharacter.cpp.obj' failed CMakeFiles\Makefile2:108: recipe for target 'CMakeFiles/core.dir/all' failed mingw32-make.exe: *** [all] Error 2 Makefile:128: recipe for target 'all' failed

Thanks you for the patience and for your help

Aucun commentaire:

Enregistrer un commentaire