【问题标题】:'sqrt' : ambiguous call to overloaded function ..\assimp\vector3.inl'sqrt' : 对重载函数的模糊调用 ..\assimp\vector3.inl
【发布时间】:2014-05-09 15:15:17
【问题描述】:

错误

错误 C2668: 'sqrt' : 对重载函数 c:\program files\assimp\include\assimp\vector3.inl 的模糊调用

当我在主 cpp 文件中包含“scene.h”时发生:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
GLFWwindow* window;
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#define MESH_FILE "cube.obj"
using namespace glm;
#include "common/shader.hpp"
#include "common/controls.hpp"

我不明白它与什么冲突?

【问题讨论】:

  • glm 命名空间是否包含 sqrt 函数?
  • @ratchetfreak 我认为是的,因为它是数学库,但为什么它们会发生冲突?
  • 因为sqrt(var) 可以指标准 sqrt 或 glm one
  • @RevanReborn:如果glm 确实包含sqrt,那么将命名空间内容转储到具有using namespace glm; 的全局命名空间将导致与C 库中的冲突。像这样污染全局命名空间绝不是一个好主意。
  • 如何结束这个问题?

标签: c++ opengl ambiguous assimp


【解决方案1】:

您的 .cpp 文件中有一个命名空间 using-directive

using namespace glm;

这意味着glm 命名空间中的所有内容都成为“全局”命名空间的一部分;所以你正在污染全局命名空间。

因此,标准 C sqrt() 函数(位于全局命名空间中)和您的 glm::sqrt() 之间可能存在某种形式的冲突,后者被“提升”为全局 sqrt

您可能想要删除上述命名空间 using 指令(当您想要引用该命名空间中的类和函数时,只需添加 glm:: 命名空间前缀)。

【讨论】:

    猜你喜欢
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 2011-12-12
    • 2014-09-05
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多