valarray is not exactly a replacement for a 3d vector class, particularly your own. There is a paper on the web by the guy who wrote it, an interesting read. To overload operators (and you can't overload . sorry) the usual way is to first overload the assignment version.
Code:
class Vector {
...
Vector & operator += (const Vector &rhs)
{
x += rhs.x; y += rhs.y; z = rhs.z;
// or x() += rhs.x(); y() += rhs.y(); z() += rhs.z();
return *this;
}
};
// then, for sugar, make a binary version
inline Vector operator +(const Vector &lhs, const Vector &rhs) {
return Vector(lhs)+=rhs;
}
The binary + invokes the copy constructor at least once, possibly twice. There is a nifty trick in The C++ Programming Language section 22.4.7 that details how to reduce temporaries and copying.
Fill your brain, holding references to pointers is almost always bad news. The assembly generated will be identical but you now have a way to unexpectedly delete something held in a reference.
As to public members/accessors don't worry about it. The main reason you want to make something private is so that you can change it later. Common ways to do 3Dvector are to either have explicit public members x,y,z or something like this
Code:
class vec3D {
enum {xpos=0, ypos=1, zpos=2};
public:
vec3D(const vec3D &vec) {
memcpy(v,vec.v,sizeof(v));
}
typedef double scalar;
scalar & x() {reutrn v[xpos];}
scalar & y() {reutrn v[ypos];}
scalar & z() {reutrn v[zpos];}
private:
scalar v[3];
};
Some things may be faster in terms of v, but you still have easily readable operations.