Array of variable length of non-POD element of type 'set <int>'
I have no idea what the problem is.
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>
using namespace std;
int main() {
ifstream infile("meeting.in");
int FF, NumPaths;
infile >> FF >> NumPaths;
int Paths[NumPaths][4];
set<int> Bessie_Times[FF];
set<int> Elsie_Times[FF];
for(int i=0;i<NumPaths;i++)
{
infile >> Paths[i][0] >> Paths[i][1] >> Paths[i][2] >> Paths[i][3];
}
sort(Paths,Paths+NumPaths);
}
In these lines, I get the following errors:
int Paths[NumPaths][4];
The array type 'int [4]' is not assigned
set<int> Bessie_Times[FF];
Error 1: array initializer must be a list of initializers
Error 2: array of variable length of non-POD element of type 'set'
Does anyone know what causes this? I searched around, but could not find anything that solved the problem. I assume that I am trying to use a variable type where I should not be, but I cannot find an instance of this.
+4
2 answers
g++ ( ). , . ++ stdlib:
#include <iostream>
#include <algorithm>
#include <fstream>
#include <set>
#include <array>
using namespace std;
int main()
{
ifstream infile("meeting.in");
int FF, NumPaths;
infile >> FF >> NumPaths;
std::vector<array<int, 4>> Paths(FF);
std::vector<set<int>> Bessie_Times(FF);
std::vector<set<int>> Elsie_Times(FF);
for(int i = 0; i < NumPaths; i++)
{
infile >> Paths[i][0] >> Paths[i][1] >> Paths[i][2] >> Paths[i][3];
}
sort(Paths.begin(), Paths.end());
return 0;
}
; ,
sort(Paths[i].begin(), Paths[i].end());
+3
int Paths[NumPaths][4];//Array type 'int[4]' is not assignable
, , . , ++ . , :
int Paths[NumPaths][4]; // wrong
int *Paths[4]; // right
for (int i = 0; i < 4; i++)
Paths[i] = new int[NumPaths];
set<int> Bessie_Times[FF];//Error 1: Array initializer must be an initializer list Error 2: variable length array of non-POD element type 'set<int>'`
, :
set<int> Bessie_Times[FF]; // wrong
set<int> *Bessie_Times = new set<int>[FF]; // right
, :
delete Paths[][];
delete BessieTimes[];
+1