如何声明转发模板模板(类)

时间:2011-04-22 20:20:44

标签: c++ templates forward-declaration

抱歉,我是模板的新手,我搜索了很多,但我找不到解决方法如何声明模板(模板)的模板。

这是我的代码:

#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”过时。

1 个答案:

答案 0 :(得分:7)

这样做

template <typename T>  class QVector;

请参阅on 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
相关问题