【发布时间】:2018-11-22 11:13:02
【问题描述】:
不明白编译错误C2676
下面的代码
#ifndef __VEC_3D_H__
#define __VEC_3D_H__
#include <vector>
#include <cmath>
namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;
/// null constructor
Vec3D(void) {}
/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};
}
#endif
我在另一个类中放置了一个功能相同的代码,它编译并运行良好。这里有什么问题?
EDIT1:将 BOBVec3d 更正为 Vec3D,是一个错字
EDIT2:删除了using namespace Internal;,将它放在头文件中确实是败笔
【问题讨论】:
-
在切线注释中,所有连续包含两个下划线的标识符以及所有以下划线和大写字母开头的标识符都被保留。在你自己的代码中定义这样的标识符是 UB。
-
将
using namespace Internal;放在标题中有点违背了拥有命名空间的目的。