Boost logo

Boost Users :

From: Ronald Garcia (garcia_at_[hidden])
Date: 2005-06-13 09:54:01


Greetings Yan,

I do not recall the context of the problem you describe below, but It
appears that the definition:

> Array (const Array& other) :
> boost::multi_array<double, 2> (other)
> {}

is the problem. the above expression will call the templated
constructor. I believe that the solution here is to cast "other" to
the multi_array type. That should result in the proper constructor
call.

HTH,
ron

On Jun 6, 2005, at 12:09 PM, Yan Zhang wrote:

> I’m read the posting by Thomas and replay by Ronald on how to inherit
> from boost::multi_array as following:
>  
>  
> On Oct 2, 2004, at 10:26 AM, Thomas Mensch wrote:
>  
> Dear List,
>  
> I am using boost 1.31.0 on Linux (with gcc 3.3.2)
> I would like to create a 2D array class, which inherits  from
> boost::multi_array<double, 2> class. However I have problems
> with the copy constructor of my class Array.  Below is the code,
> which I am trying to run.
>  
> #include <boost/multi_array.hpp>
>
> class Array
> : public boost::multi_array<double,2>
> {
> public:
> Array (void) :
> boost::multi_array<double, 2> ()
> {}
>
> Array (const int nrow, const int ncol) :
> boost::multi_array<double, 2> (boost::extents[nrow][ncol])
> {}
>
> Array (const Array& other) :
> boost::multi_array<double, 2> (other)
> {}
>
> ~Array (void)
> {}
>
> Array& operator= (const Array& rhs)
> {
> if (&rhs != this)
> {
> boost::multi_array<double, 2>::operator= (rhs);
> }
> return *this;
> }
> }; /* class Array */
>  
>  
>
> Ronald’s replay:
>
> Greetings Thomas,
>
> Though you did not supply the error message from your compiler, I
> suspect that the problem is this: multi_array has a templated
> constructor of the form:
> template <class T> multi_array(T const&);
>
> that will match your Array type better than the constructor with the
> signature:
>
> multi_array(multi_array<double,2> const&);
>
> In short, overload resolution is not selecting the constructor that
> you desire. You'll need to coerce your Array reference to a
> multi_array<double,2> reference before passing it to the constructor.
>
> Hope this helps.
>
>
> I had the same problem as Thomas’. I don’t quit understand Ronald’s
> comment. How to you overload template <class T> multi_array(T const&)
> instead of multi_array(multi_array<double,2> const&)? I thought
> Thomas’ code is overloading template <class T> multi_array(T const&).
>
>  
>
> Thanks in advance,
>
>  
>
> Yan
>
>  
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users



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