c++ - 非法引用结构中的非静态成员

标签 c++ visual-c++

使用 Visual Studio 2013 编译时出现错误

illegal reference to non-static member 'Ice::Constants::Tau

这是所有相关代码

数学.hpp

#ifndef ICE_MATHS_DEFINES_H
#define ICE_MATHS_DEFINES_H

#include "Vec2.hpp"
#include "Vec3.hpp"
#include "Vec4.hpp"
#include "Mat4.hpp"
#include "Quaternion.hpp"

namespace Ice
{
  struct Constants
  {
    static constexpr f32 Pi  = 3.14159265359;
    static constexpr f32 Tau = 6.28318530718;
  };
}

#endif

engine.cpp 中有问题的代码行

_context_scene.projection = perspective( Constants::Tau, aspect_ratio, 0.1f, 100.0f );

透视函数

  Mat4 perspective( f32 fov, f32 aspect, f32 near, f32 far );

最佳答案

我无法在 GCC 6 上重现错误。如果我让 perspective 为 Tau 参数采用 const &,那么我会得到这个错误:

constexpr-test.cpp:(.text+0x1b): undefined reference to `Constants::Tau'

否则对我来说效果很好。

我唯一的其他猜测是您的 Maths.hpp 文件中有未保存的更改。或者你在某个地方有它的第二个拷贝。在 Tau 的定义中没有static 的地方。

关于c++ - 非法引用结构中的非静态成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36900357/

相关文章:

c++ - 使用 Visual C++ 将二维数组 int[n][m] 写入 HDF5 文件

c++ - 如何强制 MSVC 编译器省略大型临时对象的堆栈分配?

c++ - 如何使用 QtMqtt 和 SSL 执行安全 MQTT?

c++ - 如何使用ndk加载Android的AAudio API

C++ 从函数指针数组调用函数

c++ - 返回一个 long long 值

c++ - 小字符串优化(调试与 Release模式)

c++ - 使用 Xcode 的 g++ 创建动态分配的数组

c++ - Qt + CMake + VC++ 生成命令提示符

c++ - 如何在 PC/Visual C++ 上查明指针是否在堆栈上