Vector operations

can342man's Avatar, Join Date: Jul 2006
Newbie Member
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's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.