diff --git a/src/core/dvector.h b/src/core/dvector.h index b061fde0c..de52deed2 100644 --- a/src/core/dvector.h +++ b/src/core/dvector.h @@ -36,14 +36,32 @@ template class DVector : public PVector { Array dvlen, dvidx; public: - explicit DVector(const PVector &sig); + explicit DVector(const PVector &shape); DVector(const DVector &v); ~DVector() override; T &operator()(int a, int b, int c); const T &operator()(int a, int b, int c) const; - DVector &operator=(T c); + DVector &operator=(const DVector &v) + { + if (this == &v) { + return *this; + } + if (dvlen != v.dvlen || dvidx != v.dvidx) { + throw DimensionException(); + } + static_cast &>(*this) = static_cast &>(v); + return *this; + } + + DVector &operator=(const Vector &v) + { + static_cast &>(*this) = v; + return *this; + } + + DVector &operator=(const T &c); }; } // end namespace Gambit diff --git a/src/core/dvector.imp b/src/core/dvector.imp index 1bf790e29..d033d9c6f 100644 --- a/src/core/dvector.imp +++ b/src/core/dvector.imp @@ -31,7 +31,7 @@ namespace Gambit { template void DVector::setindex() { int index = 1; - + for (int i = 1; i <= dvlen.Length(); i++) { dvptr[i] = this->svptr + index - 1; dvidx[i] = index; @@ -43,15 +43,17 @@ template void DVector::setindex() // DVector: Constructors, destructor, and constructive operators //-------------------------------------------------------------------------- -template DVector::DVector(const PVector &sig) - : PVector((Array)sig), dvlen(sig.Lengths().Length()), - dvidx(sig.Lengths().Length()) +template +DVector::DVector(const PVector &shape) + : PVector(static_cast &>(shape)), + dvlen(shape.Lengths().Length()), dvidx(shape.Lengths().Length()) { dvptr = new T **[dvlen.Length()]; dvptr -= 1; - for (int i = 1; i <= dvlen.Length(); i++) - dvlen[i] = sig.Lengths()[i]; + for (int i = 1; i <= dvlen.Length(); i++) { + dvlen[i] = shape.Lengths()[i]; + } setindex(); } @@ -70,7 +72,7 @@ template DVector::~DVector() if (dvptr) delete [] (dvptr + 1); } -template DVector &DVector::operator=(T c) +template DVector &DVector::operator=(const T &c) { PVector::operator=(c); return *this;