2011-04-22 88 views
0

对不起,我是新来的模板,我搜索了很多,但我不能找到一个解决方案如何声明正向模板的模板(一类) 。如何声明盼着模板的模板(一类)

这里我的代码:

#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” obsolent。

+0

为什么你不希望包括适当的头? – 2011-04-22 20:22:33

+0

@James因为他想限制qvector.h更改时重新编译的文件数量。这是一个崇高的目标。 – 2011-04-22 21:11:01

+0

@quant_dev:基于OP的以前的帖子,'QVector '是从Qt的;如果是这样,它并没有经常改变。 – 2011-04-22 21:50:37

回答

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