Boost logo

Boost Users :

From: Lang Stefan (SLang_at_[hidden])
Date: 2008-03-05 03:57:17


Hi Stefan,

My first guess would be to use initializers, as in

NetworkMultiArray::NetworkMultiArray(int length)
 : boost::multi_array<double,3>( {enter appropriate constructor
parameters here} )
{
...
}

You shouldn't need to explicitly use the this keyword unless you are
using an obscure compiler and certain syntactically obscure constructs.
However, if you want to refer to the methods of a superclass that you
have overridden in your own class, use this class's name as a qualifier,
e. g. if you have a method 'begin()' for your own class that overrides
the 'multi_array::begin()' method, you will need to write

boost::multi_array<double, 3>::begin();

Usually, when you try to extend an existing class it is a good idea to
create a typedef for your superclass, so it's easier to refer to it's
methods. In your case define a typdef like this:

typedef boost::multi_array<double, 3> super;

If you do that, you can forward calls to method overrides of your own
class to the baseclass by simply calling super::{_methodname_(...)}. E.
g. the above call would be reduced to

super::begin();

Note that some methods cannot be overriden, such as the copy
constructors or assignment operators, so you will need to provide those
for your own class and explicitely call the base class methods inside:

NetworkMultiArray& NetworkMultiArray::operator=(const NetworkMultiArray&
other)
{
   super::operator=(other); // explicit use of operator= neccessary
here!
   // copy extended stuff here
   // ...
   return *this;
}

Hope this helps!

Regards,
Stefan (another one)
 

> -----Original Message-----
>
> Message: 3
> Date: Tue, 4 Mar 2008 16:21:12 +0100
> From: "Klett, Stefan" <stefan.klett_at_[hidden]>
> Subject: [Boost-users] Extending Multi Array
> To: <boost-users_at_[hidden]>
> Message-ID:
> <53834FBAA22A7F43B76C1BCD2D5A09D3026B16A0_at_[hidden]>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi list members,
>
> This is a more or less a general kind of " how to extend container
> classes" question -
> I'm trying to write a class which inherits from
> boost::multi_array - the
> to get a kind of matrix class with some additional service routines.
> Maybe it is a lack of experience - but I for the time being I
> don't know
> how to solve the problem to access the constructor of
> multi_array in my
> own class to initialize my matrix class - my current guess was to use
> the "this" pointer but it had not worked out like I supposed
> it to do.
>
> class NetworkMultiArray: public boost::multi_array<double,3>
> {
> public:
> NetworkMultiArray(int);
> virtual ~NetworkMultiArray();
> };
>
> Here is the constructor code:
>
>
> NetworkMultiArray::NetworkMultiArray(int length)
> {
> this::iterator iter3;
> typedef this::template subarray<2>::type::iterator iter2;
> typedef this::template subarray<1>::type::iterator iter1;
>
> for( iter1 i = *this.begin(); iter1 != *this.end(); iter1++){
> for(iter2 ii = (*i).begin(); ii != (*i).end(); ii++){
> for(iter3 iii = (*ii).begin(); iii !=
> (*ii).end(); iii++){
> *iii = 0.0 ;
> }
> }
> }
> }
> sure this does not work - and is the result from trying to adapt the
> iterator example from the documentation.
>
> my aim is to handle the NetworkMultiArray like a
> boost::multi_array and
> initialize it to zero - further it would be nice if somebody
> could tell
> me how I could assign a length to the array and the subarrays.
> The key-point is that I want to use my class
> (NetworkMultiArray) like a
> multi_array by inheritance of the multi_array features of
> boost:multi_array.
>
> Thank you very much in advance.
> Best regards
> Stefan


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