我正在定义一个类,它具有指向模板类的私有成员指针。我对此类课程的设计有疑问。更准确地说,外部类是否应该被模板化。因为,我在外部类的构造函数中初始化私有成员,所以我想这样做是正确的。还有其他选择吗?下面给出了类声明的示例,欢迎所有建议:
#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;
};