使用 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/