【发布时间】:2014-01-25 23:13:19
【问题描述】:
我有一个类 Sphere(.ccp 和 .h),它有一些声明为私有的属性。我读到这些属性可以由类本身使用,但是当我尝试在 Sphere.cpp 中使用一个属性时,它说“使用未声明的标识符”。
Sphere.h:
class Sphere {
public:
inline Sphere () {}
inline Sphere (const Vec3Df spherePos, const float radius, const Material2 & mat) : spherePos(spherePos), radius(radius), mat (mat) {
updateBoundingBox();
}
virtual ~Sphere ()
{}
inline const Vec3Df getSpherePos () const { return spherePos; }
inline Vec3Df getSpherePos () { return spherePos; }
inline const float getRadius () { return radius; }
inline const Material2 & getMaterial () const { return mat; }
inline Material2 & getMaterial () { return mat; }
inline const BoundingBox & getBoundingBox () const { return bbox; }
void updateBoundingBox ();
bool intersect(Ray ray);
private:
Vec3Df spherePos;
float radius;
Material2 mat;
BoundingBox bbox;
};
我这样称呼属性:
Vec3Df pointGauche = spherePos;
有人可以帮我吗?
【问题讨论】:
-
你在成员函数中吗?
-
“类”和“文件”是不同的东西。
-
@EricFortin 是的,调用在.cpp中的函数updateboundingBox中
-
@otisonoza 这是无效的 updateBoundingBox(){ }
-
@otisonoza 我意识到我没有将 Sphere 放在 updateBoundingBox 前面。它解决了问题。
标签: c++ attributes private