I'm trying to use a vector of deques of a custom class. I've got this:
std::vector<std::deque<ParamClass<Type1,Type2>>> lines;
Where ParamClass
is a parameterized class with two class parameters. The above line is in the header (as a private variable) of another class. The constructor of that class doesn't do anything to variable lines
.
Later on in the code I try:
std::cout << lines.at(0).size() << std::endl;
This should print 0 (as nothing has been added to the deques in the vector. However, I'm getting a segfault. Do I have to somehow "initialize" the deques or something?
You are accessing element 0 but you haven't added anything so at(0) tries to access illegal memory
You need to make sure lines.size() > 0 first