Hello, I'm using boost::shared_ptr, my class overloads the operator[]. How can I access to an element of a shared pointer? class myclass { public : operator[](std::size_t) } boost::shared_ptr<myclass> x( new myclass ); How can I get an access to the [] operator? I have tried it with (*x)[5] but I'll get a "segmentation fault" error Thanks Phil
I'm using boost::shared_ptr, my class overloads the operator[]. How can I access to an element of a shared pointer? class myclass { public : operator[](std::size_t) } boost::shared_ptr<myclass> x( new myclass ); How can I get an access to the [] operator? I have tried it with (*x)[5] but I'll get a "segmentation fault" error
The syntax is correct. Ensure that shared_ptr "points" to a valid object, then debug your operator[].
On 2011-09-26 21:06:58 +0200, Igor R said:
I'm using boost::shared_ptr, my class overloads the operator[]. How can I access to an element of a shared pointer? class myclass { public : operator[](std::size_t) } boost::shared_ptr<myclass> x( new myclass ); How can I get an access to the [] operator? I have tried it with (*x)[5] but I'll get a "segmentation fault" error
The syntax is correct. Ensure that shared_ptr "points" to a valid object, then debug your operator[].
Thanks, i've found my mistake. Some pointers are pointet to null :-)
Hi,
You are doing everything correct. Make sure the overloaded operator[] is not
doing something wrong.
You may alternatively call:
x->operator[](5);
On Mon, Sep 26, 2011 at 1:50 PM, Kraus Philipp
Hello,
I'm using boost::shared_ptr, my class overloads the operator[]. How can I access to an element of a shared pointer? class myclass { public : operator[](std::size_t) }
boost::shared_ptr<myclass> x( new myclass );
How can I get an access to the [] operator? I have tried it with (*x)[5] but I'll get a "segmentation fault" error
Thanks
Phil
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Igor R
-
Kraus Philipp
-
Philipp Kraus
-
Samvel Khalatyan