Boost logo

Boost Users :

Subject: [Boost-users] shared_array const member function
From: Daya S. Prasad (mail.dsp_at_[hidden])
Date: 2009-08-26 01:00:01


Can any body please tell me why operator[] is defined in case of
shared_array<T> like this way:

Type & operator[](std::ptrdiff_t) const;

It reports compile time error. Consider the code:

class Widget {
            std::string classId;
public:
            std::string getClassId() const {
                        return classId;
            }
};

int main()
{
            boost::shared_array<Widget> obj(new Widget[10]);
            std::string id = obj[7].getClassId
(); // Error
}

In my opinion operator function should be defined as follows:

const Type & operator[](std::ptrdiff_t) const;
Type & operator[](std::ptrdiff_t) ;

Please clear my consfusion. Thanks in advance.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net