Home » Community » Newbie corner » Passing Vectors as arguments of functions.
|
|
|
Re: Passing Vectors as arguments of functions. [message #28302 is a reply to message #28301] |
Thu, 26 August 2010 20:43   |
281264
Messages: 272 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
for example, in this simple code:
#include <iostream>
#include <CtrlLib/CtrlLib.h>
using namespace std;
using namespace Upp;
struct A:Moveable<A>{
int x,y,z;
A(int x1, int y1, int z1){x=x1;y=y1;z=z1;}
};
void multi (Vector<A> a, Vector<A> b, Vector<A> c);
int main(){
Vector<A> vector_A1,vector_A2,vector_A3;
vector_A1.Add(A(10,20,30));
cout<<vector_A1[0].x<<'\n';
cout<<vector_A1[0].y<<'\n';
cout<<vector_A1[0].z<<'\n';
vector_A2.Add(A(40,50,60));
multi(vector_A1,vector_A2,vector_A3);
//cout<<vector_A3[0].x<<'\n';
//cout<<vector_A3[0].y<<'\n';
//cout<<vector_A3[0].z<<'\n';
return 0;
}
void multi (Vector<A> a, Vector<A> b, Vector<A> c){
c.Add(A(a[0].x*b[0].x,a[0].y*b[0].y,a[0].z*b[0].z));
}
why values are not passed to vector_A3? is it correct the way of passing the Vectors?
Cheers,
Javier
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sun Apr 27 01:37:55 CEST 2025
Total time taken to generate the page: 0.03437 seconds
|