用于地图的 glm 重载运算符不起作用

glm overload operator for use in map dont work

我尝试使用 glm::vec2 作为 std::map 中的键,但我有这个错误:

Severity Code Description Project File Line Suppression State Error C2678 binary '<': no operator found which takes a left-hand operand of type 'const glm::vec2' (or there is no acceptable conversion) VoxelEngine C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xstddef 239

在 google 上搜索后,我发现我需要重载运算符,我尝试使用它:

bool operator<(const glm::vec2& lhs, const glm::vec2& rhs)
{
    return lhs.x + lhs.y < rhs.x + rhs.y;
}

那是我的tools.h

#pragma once
#include <gl/glew.h>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

#include <string>
#include <fstream>
#include <iostream>
#include <math.h>


#include <..\glm/glm.hpp>
#include <..\glm/vec4.hpp>
#include <..\glm/mat4x4.hpp>
#include <..\glm/trigonometric.hpp>
// Include GLM extensions
#include <..\glm/gtc/matrix_transform.hpp>
#include <..\glm/gtc/type_ptr.hpp>
#include <..\glm/gtc/matrix_transform.hpp>
using namespace glm;
using namespace std;
bool operator<(const glm::vec2& lhs, const glm::vec2& rhs);
#include <map>

但它没有修复我的错误,我如何重载运算符?

我发现了问题,我只需要在 good 命名空间中使用重载,在我的 header 中我需要使用 :

namespace glm {
    bool operator <(const glm::vec2& l, const glm::vec2& r);
    bool operator ==(const glm::vec2& l, const glm::vec2& r);
}

谢谢大家的回答