how to make current member-function const: a problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varnie
    New Member
    • Jun 2008
    • 6

    how to make current member-function const: a problem

    good day.

    suppose i have:
    Code:
    class Key;
    class Value;
    class CList : public boost::enable_shared_from_this<CList>
    {
      std::map<Key, Value> _data;
      std::shared_ptr<CList> _pParentPtr;
    public:
        //...
        bool hasKey(const Key &key) const;
        std::shared_ptr<CList> getParent() const{
            return _pParentPtr;
        }
    };
    
    bool CList::hasKey(const Key &key) {
        boost::shared_ptr<CList> pCurList(shared_from_this()); //!
        
        bool res = false;
        do{
            res = _data.find(key) != data.end();
            pCurList = pCurList->getParent();
        } while (!res && pCurList);
      
       return res;
    }
    how can i make CList::hasKey(c onst Key &key) const ?
    thanks for clarifications.
  • varnie
    New Member
    • Jun 2008
    • 6

    #2
    i figured it out. here's solution:
    Code:
    bool CList::hasKey(const Key &key) const {
        boost::shared_ptr<CList const> pCurList(shared_from_this()); 
        bool res = false;
        do{
            res = _data.find(key) != data.end();
            pCurList = pCurList->getParent();
        } while (!res && pCurList);
       return res;
    }

    Comment

    Working...