Overloading subscript operator and working with double-pointers?

It's not clear why you are using double indirection in the first place If pixels is a double pointer to an array of pixels, you can do pixels& MyWrapper::operator (const int nIndex) { return (*Image. Pixels)nIndex; // where Image is of type image } If pixels is a pointer to an array of pointers to arrays, then you need two indices: pixels& MyWrapper::operator() ( int xIndex, int yIndex ) { return Image. PixelsyIndexxIndex; // where Image is of type image } There are a few weird things going on here typedef class { } identifier is not good C++.

Use class identifier { } or else the class has no name, so you cannot define member functions outside the class { } scope. (Among other problems. ) There is no reason to make a parameter type const int Plain int accomplishes the same thing There is no apparent reason for the double indirection.

Typically in C++ we avoid the direct use of pointers. There is probably a prepackaged standard structure you can use instead.

It's not clear why you are using double indirection in the first place. If pixels is a double pointer to an array of pixels, you can do pixels& MyWrapper::operator (const int nIndex) { return (*Image. Pixels)nIndex; // where Image is of type image } If pixels is a pointer to an array of pointers to arrays, then you need two indices: pixels& MyWrapper::operator() ( int xIndex, int yIndex ) { return Image.

PixelsyIndexxIndex; // where Image is of type image } There are a few weird things going on here. Typedef class { } identifier is not good C++. Use class identifier { };, or else the class has no name, so you cannot define member functions outside the class { } scope.(Among other problems.) There is no reason to make a parameter type const int.

Plain int accomplishes the same thing. There is no apparent reason for the double indirection. Typically in C++ we avoid the direct use of pointers.

There is probably a prepackaged standard structure you can use instead.

When using multiple indices, operator() should be preferred over operator. The latter would only work with a pair or similar structure. – larsmans Apr 8 at 8:17 @Tad: I just wasn't paying enough attention :vP .

– Potatoswatter Apr 8 at 8:31 You're right, that second overload is the correct one. Thanks. – Smartboy Apr 8 at 17:33.

I have no control over the library and can't use that, I'm forced to have to work with the double pointer, whih is why I asked. – Smartboy Apr 8 at 13:38.

This is more typical, for c++: #include namespace AA { class t_point { public: t_point(const size_t& X, const size_t& Y) : d_x(X), d_y(Y) { } const size_t& x() const { return this->d_x; } const size_t& y() const { return this->d_y; } private: size_t d_x; size_t d_y; }; class t_array { public: // abusive, but possible. Prefer `at` const int& operator(const t_point& idx) const { return this->at(idx.x(), idx.y()); } const int& at(const t_point& idx) const { return this->at(idx.x(), idx.y()); } const int& at(const size_t& x, const size_t& y) const { return this->d_objectsxy; } private: // or use your c image representation... std::vector > d_objects; private: static const int& ctest(const t_array& arr) { const t_point pt(1, 2); return arrpt; return arr. At(pt); return arr.At(pt.

D_x, pt. D_y); } }; } the big problem with using one index in this case it that it is not clear which index (pixel) you are attempting to access, while pushing all the coordinate calculations off to the client. If it's a single pointer, you'd still push the problem onto the client, but you'd be able access the index predictably.

With double... the layout in memory can vary, it is not necessarily contiguous. It's just a bad design to publish it as a single value (logically, as a 1D array), rather than a 2D array or a point (for example).

I have no control over the library and can't use that, I'm forced to have to work with the double pointer, whih is why I asked. – Smartboy Apr 8 at 13:46 ok. The syntax will be the same as written op and at.

Using this c interface, you'll have to add your own logic for bounds checking, memory management, copying, constructing with offsets, coordinate offsets (where applicable) and so on. The subscript notation just functions as a multiply by the element offsets by the index you desire. The first will determine the address of either a row or column of pixels, then second will return then apply another offset for the pixel in the row or column.

– Justin Apr 8 at 17:16.

There is no apparent reason for the double indirection. Typically in C++ we avoid the direct use of pointers. There is probably a prepackaged standard structure you can use instead.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions