在结构中非法引用非静态成员

时间:2016-04-27 20:35:49

标签: c++ visual-c++

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

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

这就是所有相关的代码

Maths.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 );

1 个答案:

答案 0 :(得分:0)

我无法在GCC 6上重现错误。如果我让perspective为Tau参数取const &,那么我可能会收到此错误:

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

否则它对我来说很好。

我唯一的另一个猜测是你的Maths.hpp文件中有未保存的更改。或者你在某个地方有第二份副本。某个地方你没有关于Tau的定义static