如何输入内部类

How to typedef an inner class

本文关键字:内部类 输入 何输入      更新时间:2023-10-16

我有一个矩阵类和一个列类:

template<class T>
struct MatrixT
{
    template<class T>
    struct ColumnT
    {
    };
};

请注意,ColumnT始终保持与MatrixT相同的类型。

为方便我定义

typedef MatrixT<double> matrix;

由于实际上,我大部分时间都会使用double元素。但是我也想定义columnT类相似的内容。我尝试了

typedef MatrixT<double>::ColumnT<double> matrix::column;

但汇编失败,错误

错误 - 不允许合格名称

是否有一种实现我想要的方法?

我希望能够键入matrix::column c;,就像我可以键入matrix m;

只需删除第二个template<class T>

template<class T>
struct MatrixT
{
    struct ColumnT
    {
    };
};

ColumnT应该使用与MatrixT相同的类型,并且您的Typedef ...

typedef MatrixT<double> matrix;

...应该按照您的期望工作。