c++ - 将使用 typedef 创建成员

标签 c++ typedef

我是 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/

相关文章:

c++ - Pugixml C++解析XML

c - 在 C 中定义类似 int 的类型

编译器错误可能与 typedef 有关

c++ - "typedef sometype sometype"有什么意义?

c++ - 三个有符号整数的哈希函数

c++ - "unable to initialize application 0xc000005"

c++ - 请帮助......无法编译 "Point Cloud Library"

c - 创建函数指针结构时指针类型不兼容

c - C 中的 struct typedef。变量还是类型?

c++ realloc 性能 vs malloc