如何声明模板的模板(类的模板)

How to declare foward a template of template (of a class)

本文关键字:声明 何声明      更新时间:2023-10-16

对不起,我是模板新手,我搜索了很多,但我找不到一个解决方案,如何声明转发模板的模板(类的)。

下面是我的代码:

#ifndef CMAP_H
#define CMAP_H
#include "qvector.h"
class CMap
{
public:
    CMap(const unsigned int & width, const unsigned int & height, const unsigned int & hexagonRadius);
    CMap(const unsigned int & width, const unsigned int & height, const unsigned int & hexagonRadius, const QVector<QVector<unsigned int> > & landType);
    ~CMap();
private:
    class Pimple;
    Pimple * d;
};
#endif // CMAP_H

我只是想让#include "qvector.h"过时。

这样做

template <typename T>  class QVector;

参见codepad:

#ifndef CMAP_H
#define CMAP_H
template <typename T>  class QVector;
class CMap
{
public:
    CMap(const unsigned int & width, const unsigned int & height, const unsigned int & hexagonRadius);
    CMap(const unsigned int & width, const unsigned int & height, const unsigned int & hexagonRadius, const QVector<QVector<unsigned int> > & landType);
    ~CMap();
private:
    class Pimple;
    Pimple * d;
};
#endif // CMAP_H