【发布时间】:2014-02-28 15:18:52
【问题描述】:
FCORE 宏用于共享库导出。
这是我的头文件 FMath.h
namespace FMath {
// ...
FCORE const float PI_32 = 3.14159265359f; // pi
FCORE inline float Floor(float value) { return floorf(value); }
namespace FConvert {
// ...
FCORE const float DEG_TO_RAD_32 = 0.01745329252f; // pi / 180
FCORE inline float ToRadian(float degree) { return degree * DEG_TO_RAD_32; }
}
}
我的 FConvert 命名空间中的所有常量值都会导致错误,但不会在 FMath 中声明。我不明白为什么?
FMeshTraits.obj:-1: 错误: LNK2005: DEG_TO_RAD_32 已经定义在 FMesh.obj
编辑:对不起,我没有说我已经使用过这个宏。
#ifndef FMATH_H
#define FMATH_H
// All of the code is here
#endif
【问题讨论】:
-
你在多个 TU 中定义了同一个变量,所以多个对象都有它。您可以尝试使用静态或匿名命名空间使它们在每个 TU 中唯一,或者仅在一个 TU 中定义它们。
-
请您解释一下吗?
-
什么是FCORE?你能展示一下吗?是否包含关键字 extern?
-
很抱歉我没有看到这个。 FCORE 是来自 Qt 的共享库指令 (Q_SHARED_EXPORT, Q_SHARED_IMPORT)
标签: c++ constants header-files