2011-03-04 71 views
0

用下面的執行STL容器名單,我試圖回答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; 
}; 

問: 我可以代替「列表的鍵盤」代替「qwertyWrap鍵盤」類ASDF並實現與STL列表相同的功能?

+0

如果您不使用它,則可以使用int替換列表。你在「鍵盤」上實際嘗試使用什麼方法/概念? – BatchyX 2011-03-04 09:47:22

+0

@BatchyX - 我打算使用qwertyWrap鍵盤使用類wlist和類qwerty的方法。 – codebin 2011-03-04 19:20:54

回答

0

回答我最初的問題: /*問題/ /可以在以下聲明可通過qwertyWrap鍵盤取代??? */ 列表鍵盤;或qwertyWrap鍵盤;

qwertyWrap鍵盤可以替代列表鍵盤並仍然保持std :: list功能。我也在某個時候實施了這個解決方案。

0

A list needs more。這個鏈接只是一個指針。要絕對確定,你必須查閱官方標準。

+0

但由於qwertyWrap繼承自wlist,不是qwertyWrap鍵盤std :: list的一個對象??? – codebin 2011-03-04 10:02:56

+0

@codebin:'wlist'不是'std :: list',它只包含一個'std :: list'。此外,你[不應該從標準容器繼承](http://stackoverflow.com/questions/2034916/)。 – 2011-03-04 10:06:11

+0

qwertyWrap鍵盤怎麼樣; keyboard.resize(some_number);這當然會做我猜的伎倆。 – codebin 2011-03-06 00:17:23