Bug #410

Reading a field from one vector and writing it to a second vector fails

Added by Anonymous about 13 years ago. Updated almost 13 years ago.

Status:ResolvedStart date:07/11/2011
Priority:HighDue date:
Assignee:M. Rolf% Done:

100%

Category:-Estimated time:1.00 hour
Target version:NemoMath 0.1

Description

Example code:

#include <iostream>
#include "Vector.h"
int main() {
nemo::RealVector values = nemo::RealVector(4); // 4-dim. vector
unsigned int dim = values.dimension() / 2; // 2
nemo::RealVector tmpA(dim), tmpB(dim); // 2-dim. vectors
for (unsigned int index = 0; index < dim; ++index) {
tmpA[index] = values[2 * index];
tmpB[index] = values[2 * index + 1];
}
std::cout << tmpA << std::endl;
std::cout << tmpB << std::endl;
}

Error is:

nemo/Vector.h: In member function ‘nemo::MathVector&lt;double&gt;::ReadWriteRef& nemo::MathVector&lt;double&gt;::ReadWriteRef::operator=(const nemo::MathVector&lt;double&gt;::ReadWriteRef&)’:
nemo/Vector.h:151: error: non-static reference member ‘nemo::IntrusiveCowSupport&lt;nemo::MathVector&lt;double&gt;::VectorData&lt;double&gt; >& nemo::MathVector&lt;double&gt;::ReadWriteRef::data’, can't use default assignment operator
examples/Crash.cpp: In function ‘int main()’:
examples/Crash.cpp:12: note: synthesized method ‘nemo::MathVector&lt;double&gt;::ReadWriteRef& nemo::MathVector&lt;double&gt;::ReadWriteRef::operator=(const nemo::MathVector&lt;double&gt;::ReadWriteRef&)’ first required here

History

#1 Updated by M. Rolf about 13 years ago

  • Status changed from New to In Progress

#2 Updated by M. Rolf about 13 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

New test code:

// non-const operator[]
RealVector v1(2, 1.0);
RealVector v1B(v1);
RealVector v2(2, 2.0);
RealVector v2B(v2);
v1[0] = v2[0];
// const operator[]
const RealVector c1(2, 3.0);
const RealVector c1B(c1);
v1[0] = c1[0];
// use non-const[] inside something else
RealVector z(2, 0.0);
double a = std::sin(z[0]);
double b = 2*v1[1] + v2[1];

#3 Updated by M. Rolf almost 13 years ago

  • Target version set to NemoMath 0.1

Also available in: Atom PDF