Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何创建模板化对象的数组/向量_C++_Arrays_Templates_Vector - Fatal编程技术网

C++ 如何创建模板化对象的数组/向量

C++ 如何创建模板化对象的数组/向量,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

我有一个模板类,它是作为MFC
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;
};