我正在定义一个具有私有成员指向模板类的类的类。我有一个关于这样的课程设计的问题。更确切地说,外部类是否应该被模板化。 因为,我正在初始化外部类的构造函数中的私有成员,我想,这样做是正确的。还有其他的选择吗? 一类声明的例子如下,所有建议都欢迎:设计嵌套模板类
#include <foo.h>
#include <bar.h>
template < class FOO_TYPE, class BAR_TYPE >
class OuterClass{
public:
OuterClass(){
this->m_pFoo = new CFoo<FOO_TYPE>();
this->m_pBar = new CBar<BAR_TYPE>();
this->m_nMyInt = 0;
}
template < class FOO_TYPE >
CFoo<FOO_TYPE> * processFoo();
template < class BAR_TYPE >
CBar<BAR_TYPE> * processBar();
~OuterClass(){
delete this->m_pFoo;
delete this->m_pBar;
}
private:
int m_nMyInt;
CFoo<FOO_TYPE> * m_pFoo;
CBar<BAR_TYPE> * m_pBar;
};
+1“3的规则”,我不能相信我错过了。 – Mephane 2010-11-29 14:48:55