assigning a value to a matrix shared_ptr

Hello, I am trying to assign a value to the matrix, which is pointed to by the shared pointer, but I am not sure which operator to call, please have a look at the following code, I commented the problem: #include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; matrix<double> m (3, 3); boost::shared_ptr<matrix<double>> m2(new matrix<double>(3,3)); for (unsigned i = 0; i < m.size1 (); ++ i) for (unsigned j = 0; j < m.size2 (); ++ j) { m (i, j) = 3 * i + j; /// now do the same operation to the shared pointer's matrix m2->operator*(i, j) = 3 * i + j; // this results in a runtime error } std::cout << m << std::endl; // And how do we print m2 ? } Thanks, Max

This is the best that I could come up with: for (unsigned i = 0; i < m2->size1(); ++i) for (unsigned j = 0; j < m2->size2(); ++j) m2->insert_element(i, j, 3 * i + j); std::cout<<m2.operator *()<<std::endl; Is there a more elegant solution? Cheers, Max On Tue, Jul 27, 2010 at 8:40 PM, Max S. Kaznady <max.kaznady@gmail.com> wrote:
Hello,
I am trying to assign a value to the matrix, which is pointed to by the shared pointer, but I am not sure which operator to call, please have a look at the following code, I commented the problem:
#include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp>
int main () { using namespace boost::numeric::ublas; matrix<double> m (3, 3); boost::shared_ptr<matrix<double>> m2(new matrix<double>(3,3)); for (unsigned i = 0; i < m.size1 (); ++ i) for (unsigned j = 0; j < m.size2 (); ++ j) { m (i, j) = 3 * i + j; /// now do the same operation to the shared pointer's matrix m2->operator*(i, j) = 3 * i + j; // this results in a runtime error } std::cout << m << std::endl; // And how do we print m2 ? }
Thanks, Max

I guess this works too: for (unsigned i = 0; i < m2->size1(); ++i) for (unsigned j = 0; j < m2->size2(); ++j) (*m2)(i, j) = 3 * i + j; std::cout<<*m2<<std::endl; Cheers, Max On Tue, Jul 27, 2010 at 9:12 PM, Max S. Kaznady <max.kaznady@gmail.com> wrote:
This is the best that I could come up with: for (unsigned i = 0; i < m2->size1(); ++i) for (unsigned j = 0; j < m2->size2(); ++j) m2->insert_element(i, j, 3 * i + j); std::cout<<m2.operator *()<<std::endl;
Is there a more elegant solution?
Cheers, Max
On Tue, Jul 27, 2010 at 8:40 PM, Max S. Kaznady <max.kaznady@gmail.com> wrote:
Hello,
I am trying to assign a value to the matrix, which is pointed to by the shared pointer, but I am not sure which operator to call, please have a look at the following code, I commented the problem:
#include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp>
int main () { using namespace boost::numeric::ublas; matrix<double> m (3, 3); boost::shared_ptr<matrix<double>> m2(new matrix<double>(3,3)); for (unsigned i = 0; i < m.size1 (); ++ i) for (unsigned j = 0; j < m.size2 (); ++ j) { m (i, j) = 3 * i + j; /// now do the same operation to the shared pointer's matrix m2->operator*(i, j) = 3 * i + j; // this results in a runtime error } std::cout << m << std::endl; // And how do we print m2 ? }
Thanks, Max
participants (1)
-
Max S. Kaznady