0

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????

Community
  • 1
  • 1
codebin
  • 285
  • 1
  • 4
  • 12
  • you can substitude list with an int if you don't use it. what methods/concept do you actually attempt to use on 'keyboard' ? – BatchyX Mar 04 '11 at 09:47
  • @BatchyX - I intend to use methods of both class wlist and class qwerty using qwertyWrap keyboard. – codebin Mar 04 '11 at 19:20

2 Answers2

0

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

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
  • But since qwertyWrap is inherited from wlist, isn't qwertyWrap keyboard an object of std::list ??? – codebin Mar 04 '11 at 10:02
  • @codebin: `wlist` is not an `std::list`, it just contains an `std::list`. Also, you [should not inherit from a standard container](http://stackoverflow.com/questions/2034916/). – Björn Pollex Mar 04 '11 at 10:06
  • How about qwertyWrap keyboard; keyboard.resize(some_number); This certainly will do the trick I guess. – codebin Mar 06 '11 at 00:17
0

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.

codebin
  • 285
  • 1
  • 4
  • 12