2011-04-22 41 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