我正在尝试编写康威的"生命游戏".在接近我的目标时,我遇到了编译错误:
C2338:C++库不提供此类型的哈希值.
起初我使用了SFML类sf::Vector2D.当它无法为我工作时,我写了一个属于我自己的类,希望我能实现丢失的hashCode方法.
我的问题是:
是否可以使用我自己的类使用自己的hashCode方法std::unordered_map?我需要使用一个可以容纳两个数字的类.(我也尝试过std::tuple,但是struct东西).
这是我的一张代码:
#include "GameMechanics.h"
GameMechanics::GameMechanics(Elements * elements):elements(elements)
{
this->refreshTime = 1000000; //ms
this->clock.restart();
}
GameMechanics::~GameMechanics()
{
}
bool GameMechanics::isRunning()
{
return this->running;
}
void GameMechanics::setRunning(bool running)
{
this->running = running;
}
void GameMechanics::loop()
{
unsigned passedTime = clock.getElapsedTime().asMicroseconds(); //check passed time since the clock got restarted
this->timeHeap += passedTime; //add passed time to the timeheap
this->clock.restart();
//only refresh every "refreshTime" seconds
if (timeHeap >= …Run Code Online (Sandbox Code Playgroud)