Greetings Yan,
I do not recall the context of the problem you describe below, but It
appears that the definition:
Times New RomanArray
(const Array& other) :
Times New Roman
boost::multi_array< (other)
Times New Roman {}
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:
Courier NewI’m
read the posting by Thomas and replay by Ronald on how to inherit from
boost::multi_array as following:
Courier New
Courier New
Courier NewOn Oct 2,
2004, at 10:26 AM, Thomas Mensch wrote:
Courier New
Courier NewDear List,
Courier New
Courier NewI am using
boost 1.31.0 on Linux (with gcc 3.3.2)
Courier NewI would
like to create a 2D array class, which inherits from
Courier Newboost::multi_array< class. However I have problems
Courier Newwith the
copy constructor of my class Array. Below is the code,
Courier Newwhich I am
trying to run.
Courier New
Times New Roman#include
<
Times New Roman class Array
Times New Roman : public
boost::multi_array<
Times New Roman {
Times New Roman public:
Times New Roman Array
(void) :
Times New Roman
boost::multi_array< ()
Times New Roman {}
Times New Roman Array
(const int nrow, const int ncol) :
Times New Roman
boost::multi_array< (boost::extents[nrow][ncol])
Times New Roman {}
Times New Roman Array
(const Array& other) :
Times New Roman
boost::multi_array< (other)
Times New Roman {}
Times New Roman ~Array
(void)
Times New Roman {}
Times New Roman Array&
operator= (const Array& rhs)
Times New Roman {
Times New Roman if (&rhs !=
this)
Times New Roman {
Times New Roman
boost::multi_array<::operator= (rhs);
Times New Roman }
Times New Roman return
*this;
Times New Roman }
Times New Roman }; /* class
Array */
Arial
Courier New
Times New RomanRonald’s
replay:
Times New RomanGreetings
Thomas,
Times New Roman 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:
Times New Roman template
< multi_array(T const&);
Times New Roman that will
match your Array type better than the constructor with the signature:
Times New Roman
multi_array(multi_array< const&);
Times New Roman In short,
overload resolution is not selecting the constructor that you desire.
You'll need to coerce your Array reference to a multi_array<
reference before passing it to the constructor.
Times New Roman Hope this
helps.
Times New RomanI had the
same problem as Thomas’. I don’t quit understand Ronald’s comment. How
to you overload template < multi_array(T const&) instead of
multi_array(multi_array< const&)? I thought Thomas’ code is
overloading template < multi_array(T const&).
Times New Roman
Times New RomanThanks in
advance,
Times New Roman
Times New RomanYan
Times New Roman
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users