Hi to everyone, I've to do the following exercise, Given a global vector gv, I have to define a function f() which takes a vector as argument, such that:
1)Inside the function there is a local vector lv.
2)lv must be initialized with the same values of gv (they have the same size by construction).
3) Print out the elements of lv
4)Define a second local vector lv2 which must be initilaized with the same elements of the f()'s argument and then print its values.
The problem is the point 3), up to now I've done:
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include "std_lib_facilities.h"
vector<int> gv = {1,2,3,4,5,6,7,8,9,10};
void f(vector<int> qv[10])
{
vector<int> lv[10];
for (int i = 0; i < 10; i++)
{
lv[i] = gv[i];
}
for (int i = 0; i < 10; i++) cout << lv[i] << "\n;"
}
void f(int ga[], int a)
{
int la[10];
for (int i = 0; i < a; i++)
{
la[i] = ga[i];
}
int* p2 = new int[10];
int* p = p2;
for (int i = 0; i < a; i++)
{
p[i] = ga[i];
}
for (int i = 0; i < a; i++) cout << la[i] << "\n";
for (int i = 0; i < a; i++) cout << p[i] << "\n";
delete[] p;
}
int main()
{
system("pause");
return 0;
}
|
But i obtain this error in the second for cicle inside f(vector):
1>c:\users\angmarwizardking\documents\visual studio 2015\projects\ch18\drillvector\drillvector\source.cpp(13): error C2679: binary '<<': no operator found which takes a right-hand operand of type 'Vector<int>' (or there is no acceptable conversion)
The f(vector ) should do the same thing of the function below f(array, int).
I presume that the error is in the syntax of the local vector, but I'm not able to find it.
Thank to everyone.