I am trying to implement the fractional knapsack famous problem. I needed a struct to connect the values and the weights. Now I want to read the array of struct item, but it gives me this:
invalid expression error
#include <iostream>
#include <vector>
#include <string>
using std::vector;
using namespace std;
// Structure for an item which stores weight and corresponding
// value of Item
struct Item
{
int value, weight;
// Constructor
Item(int value, int weight) : value(value), weight(weight) {}
};
int main()
{
int n;
int W;
std::cin >> n >> W;
vector<Item> arr(n);
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
cout << "Maximum value we can obtain = " << fractionalKnapsack(W, arr, n);
return 0;
}