Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Vector operations (http://www.go4expert.com/forums/vector-operations-t1251/)

can342man 21Aug2006 21:02

Vector operations
 
I have been wondering why a simple vector manipulation scheme as the one below is not valid. The compiler says that the multipilcation (*3.0) operation does not exist.

I am not sure how to use the std::vector library for this purpose. Would that method work in which the function vVAdd() would return a vector type and allow the multiplication?

Much appreciation if anyone can help.

Code:

#include <iostream>
#include <fstream>
using namespace std;

//class for vectors
class Vect {
public:
    double x, y, z;  // vector units
};

void vVAdd(Vect &v, Vect v1, Vect v2);

int main ()
{
 Vect t1, t2, t3, t4;

 t1.x = 4.0, t1.y = 5.5, t1.z = 7.1;
 t2.x = 3.6, t2.y = 4.8, t2.z = 3.6; 
   
 vVAdd(t3, t1, t2);
 t4 = t3*3.0;
 
 cout << t4.x << '\t' << t4.y << '\t' << t4.z << endl;
   
}   

void vVAdd(Vect &v, Vect v1, Vect v2)

  v.x = v1.x + v2.x;                                           
  v.y = v1.y + v2.y;
  v.z = v1.z + v2.z;
 
return;
}


shabbir 24Aug2006 06:56

Re: Vector operations
 
Welcome to G4EF. You probably posted the query in the wrong section. I have moved it at the correct place.

You are operating on the object (*3.0) but that is allowed only when you have an overloaded operator.


All times are GMT +5.5. The time now is 13:48.