我是 C++ 编程的新手。所以这个问题对你来说可能听起来很愚蠢。
class ABCD : public VectorS<UINT8, 50>
{
private:
typedef VectorS<UINT8, 50> XYZ;
float m_length;
float m_angle;
inline void append_check (const Point2D& pt)
{
if (!full())
{
push_back (pt);
}
}
public:
typedef Point2Df Point;
ABCD() : m_length(0), m_angle(0) {}
void copy (const ABCD& def)
{
XYZ::operator=(def);
m_length = def.getLength();
m_angle = def.getAngleBound();
}
void clear (void)
{
XYZ::clear();
}
}
这里 XYZ 的 typedef 发生了什么?将使用此 typedef 创建 vector 吗?我看不到任何创建的 XYZ 类型的成员变量。 XYZ::clear() 会发生什么?这里清除了什么?
最佳答案
此代码使用 typedef
为其父类创建一个较短的名称,VectorS<UINT8, 50>
.
void clear (void)
{
XYZ::clear();
}
与
相同void clear (void)
{
VectorS<UINT8, 50>::clear();
}
与
相同void clear (void)
{
this->VectorS<UINT8, 50>::clear();
}
即它正在调用 clear
从其父类继承的方法。
关于c++ - 将使用 typedef 创建成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38146935/