1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <fstream>
using namespace std;
class Vector3D {
private:
double x, y, z;
public:
Vector3D (double x=0, double y=0, double z=0) : x(x), y(y), z(z) {
}
friend ostream& operator << (ostream& s, Vector3D v){
return s << v.x << "," << v.y << "," << v.z;
}
double Vector3D::dot (const Vector3D& b){
return (b.x, b.y, b.z);
}
};
int main() {
Vector3D a(0.5, 2.0, 2.0);
Vector3D b(-2, 1, 0);
double c = a.dot(b); // 0.5*-2 + 2.0*1.0 + 2.0* 0.0 = 1.0
cout << d << '\n';
|