2015-01-29 24 views
0

Linux (Ubuntu)에서 다른 사람의 프로젝트를 컴파일하려고하는데, SDL2를 사용하는 게임입니다. GCC4.8.2와 C++ 11 플래그를 사용하여 Code :: Blocks로 컴파일 중이다. 나는 실수를 인터넷에서 보거나 심지어 그것을 이해하기 위해 라스 시간을 보내지 만 운이 전혀 없다. 나는 누군가가 저를 도울 수 있거나 적어도 저에게지도를 줄 수 있기를 바랍니다. 도움이된다면 Position.h에 대한 코드,std :: unordered_map (Ubuntu - GCC4.8.2)에서 C++ 오류가 발생했습니다.

#ifndef __FLOOR_H__ 
#define __FLOOR_H__ 
#include <vector> 
#include <unordered_map> 


#include "Position.h" 

//class SDLGameObject; 
#include "SDLGameObject.h" 

// Floor stores elements on that floor 

class Floor { 

public: 
    std::unordered_map<Position, SDLGameObject*, PositionHash> elements; // Line of the error 
    std::vector<std::vector<SDLGameObject*> > map;// Map 

public: 
    Floor(); 
    ~Floor(); 

    void render(); 
    void cleanUp(); 
}; 
#endif 

그리고 :

#ifndef __POSITION_H__ 
#define __POSITION_H__ 

class Position { 
public: 
    int x_coord; 
    int y_coord; 

public: 
    Position(int x, int y):x_coord(x),y_coord(y){} 

    bool operator==(const Position& other) const { 
    return x_coord == other.x_coord && 
      y_coord == other.y_coord; 
    } 

}; 

class PositionHash { 

public: 
    std::size_t operator()(const Position* p) const { 
     // 16 is the maximum value in the pair of coordination integers 
     return p->x_coord * 16 + p->y_coord; 
    } 
}; 

#endif 

/usr/include/c++/4.8/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash<Position, PositionHash>’: 
/usr/include/c++/4.8/type_traits:121:12: recursively required from ‘struct std::__and_<std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> >’ 
/usr/include/c++/4.8/type_traits:121:12: required from ‘struct std::__and_<std::__is_fast_hash<PositionHash>, std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> >’ 
/usr/include/c++/4.8/type_traits:127:38: required from ‘struct std::__not_<std::__and_<std::__is_fast_hash<PositionHash>, std::is_default_constructible<PositionHash>, std::is_copy_assignable<PositionHash>, std::__detail::__is_noexcept_hash<Position, PositionHash> > >’ 
/usr/include/c++/4.8/bits/unordered_map.h:99:66: required from ‘class std::unordered_map<Position, SDLGameObject*, PositionHash>’ 
/home/*/*/games/magictower/Magic-Tower/Floor.h:17:61: required from here 

그리고 Floor.h에 대한 코드 :

오류는 미리 감사드립니다 !!!!

답변

0

는 당신이이

std::unordered_map<Position, SDLGameObject*, PositionHash> 

키가 Position하는 Poisition포인터을 복용 한 후 해시 함수

std::size_t operator()(const Position* p) const 

하는지도.

맵은 해시 함수에 키 (Position 값)를 전달하지만 해시 함수는 값 (또는 참조)을 취하지 않으며 포인터를 사용하며 오류가 발생한 곳입니다. 대신 참조를 사용하도록 해시 함수를 변경하십시오.

std::size_t operator()(const Position& p) const 
+0

모든 설명을 주셔서 감사합니다 .... 나중에 집에서 시험해 보겠습니다. 정말 고마워요. 어떻게 됐는지 말해 줄께! – JetSpyDragon

+0

PositionHash의 마지막 코드는 다음과 같습니다. std :: size_t operator() (const Position & p) const, 말했듯이 반환 부분은 return p.x_coord * 16 + p.y_coord; 감사! – JetSpyDragon