开发者

Substituting STL List container with class pointer

开发者 https://www.devze.com 2023-02-15 06:09 出处:网络
With the following implementation, I\'m attempting to answer my question: class wlist { private:     std::开发者_开发百科list<void*> m_list;

With the following implementation, I'm attempting to answer my question:

class wlist
{
private:
    std::开发者_开发百科list<void*> m_list;

public:

    unsigned int size () { return m_list.size(); }
    bool empty () { return m_list.empty(); }
    void pop_back () { m_list.pop_back(); }
    void pop_front () { m_list.pop_front(); }
};

class qwertyWrap : public wlist
{
public:
    int getNumber() { ptr->getNumber(); }
    void setNumber(int x) { ptr->setNumber(x); }

private:
    qwerty* ptr;
};

class qwerty
{
public:
    int getNumber();
    void setNumber(int x);
};


class asdf
{
public:
    int getElement();
    void setElement(int x);
private:
    /* Question */
    /* Can the following declaration be substituted by qwertyWrap keyboard ??? */
    list<qwerty*> keyboard; or qwertyWrap keyboard;
};

Question: Can I substitute "qwertyWrap keyboard" in place of "list keyboard" in class asdf and achieve the same functionality as that of a STL list????


No. A list needs more. This link is just a pointer. To be absolutely sure, you would have to consult the official standard.


Answer to my initial question: /* Question / / Can the following declaration be substituted by qwertyWrap keyboard ??? */ list keyboard; or qwertyWrap keyboard;

qwertyWrap keyboard can be substituted for list keyboard and still maintain the std::list functionality. I've also implemented this solution sometime back.

0

精彩评论

暂无评论...
验证码 换一张
取 消