Substituting STL List container with class pointer
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.
精彩评论