C++ 如何创建模板化对象的数组/向量
我有一个模板类,它是作为MFCC++ 如何创建模板化对象的数组/向量,c++,arrays,templates,vector,C++,Arrays,Templates,Vector,我有一个模板类,它是作为MFCCWnd对象包装器的模板 在main类中,我希望有一个面板控件的集合,但我不知道如何创建它们的数组,因为它们显然是从不同的基类(即CButtonCtrl、CListBox等)派生的 模板 类组件:公共W { 公众: 组件(uint_t nId=-1,CWnd*pParent=NULL,const char*pName=NULL) :mParent(pParent) ,mName(pName) ,中(nId) { //std::cout您可能想尝试boost::any
CWnd
对象包装器的模板
在main类中,我希望有一个面板控件的集合,但我不知道如何创建它们的数组,因为它们显然是从不同的基类(即CButtonCtrl、CListBox等)派生的
模板
类组件:公共W
{
公众:
组件(uint_t nId=-1,CWnd*pParent=NULL,const char*pName=NULL)
:mParent(pParent)
,mName(pName)
,中(nId)
{
//std::cout您可能想尝试boost::any
或std::any
您可能想尝试boost::any
或std::any
“模板化对象”没有多大意义。模板适用于类型或函数。“模板化对象”没有多大意义。模板适用于类型或函数。
template<typename W>
class Component : public W
{
public:
Component(uint_t nId = -1, CWnd *pParent = NULL, const char *pName = NULL)
: mParent(pParent)
, mName(pName)
, mId(nId)
{
//std::cout << ((mName != NULL) ? mName : "NULL") << ": " << (void *)this << ": Id:" << mId << " Parent:" << (void *)mParent << std::endl;
}
const char *getName(void) const { return mName; }
void setId(uint_t nId) { mId = nId; }
uint_t getId(void) const { return mId; }
void setParent(CWnd *pParent) { mParent = pParent; }
CWnd *getParent() const { return mParent; }
private:
uint_t mId;
CWnd *mParent;
const char *mName;
};
class Panel : public Component<CDialog>
{
public:
Panel(uint_t nId = -1, CWnd *pParent = NULL, const char *pComponentName = NULL);
virtual ~Panel(void) {};
virtual void CreateWnd(CWnd *pParent = NULL);
template <typename W>
void addComponent(Component<W> *pComponent)
{
}
template <typename W>
void removeComponent(Component<W> *pComponent)
{
}
void Show(bool bShow = true) override;
protected:
typedef std::vector<Component<?> *> Components;
private:
Components mComponents;
};