I cannot get the following code to compile:
Code:
include <vector>
#include <iostream>
using namespace std;
int WeirdProduct( const vector<float> & V1, const vector<float> & V2)
{
int product = 1, minsize;
if( V1.size() < V2.size())
minsize = V2.size();
for(int i=0; i < minsize; i++)
if( V2[i] < 0 )
product = product * i;
return product;
}
void main ()
{
const vector<float> V1(4);
const vector<float> V2;
float array[]={42.3,21.5,-3.1,-4.2,155.8,33.7,-1.9};
for(int i=0; i<=7; i++)
V2.push_back(array[i]);
WeirdProduct(V1,V2);
}
The problem is the V2.push_back(array[i])
line in void main. The error received when trying to compile is :
weird.cpp: In function `int main(...)':
weird.cpp:21: passing `const vector<float,allocator<float> >' as `this' argument of `voi
d vector<float,allocator<float> >:ush_back(const float &)' discards qualifiers
Which I presume is an issue with data types of some sort. I am trying to insert the data from a c style array into a vector array via the for loop based upon the value of i, any help would be much appreciated.
Code tags added by Kermi3