dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #18568
Operator overloading for Vector
-
To:
dolfin@xxxxxxxxxxxxxxxxxxx
-
From:
Florian Rathgeber <frat@xxxxxx>
-
Date:
Thu, 17 Jun 2010 20:23:50 +0200
-
User-agent:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Lightning/0.9 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666
Hi,
I was wondering why +=, *=, etc. are overloaded in the Vector class, but
not addition of Vectors and multiplication of Vectors by scalars.
Hence I tried the following:
namespace dolfin
{
Vector operator*( double a, const Vector& v )
{
Vector res( v );
res *= a;
return res;
}
Vector operator*( const Vector& v, double a )
{
Vector res( v );
res *= a;
return res;
}
Vector operator+( const Vector& v1, const Vector& v2 )
{
Vector res( v1 );
res += v2;
return res;
}
}
but realized the construction of the return object is not possible since
the copy constructor of Vector is explicit.
Is that a design decision that this is not supposed to be possible? I
realize that creating a temporary Vector can be quite expensive.
Florian
Follow ups