So right now I have a class, called Set, in C++. In it, I have an integer called mCardinality, and an integer array called mElements. I want to be able to accept an integer in the constructor for mCardinality, then use this to assign a size to my integer array, is there any way to do this, or do I absolutely have to have a size for it right off the bat?
(I guess I could just make the size the maximum integer, then only use the cardinality for limiting the loops where I deal with the elements, but a neater solution would be preferable).
I did see on here that there may be a way to use std::vector to resize an array, will that work? And…how would that code look? And do vectors work just like arrays in C++ for everything else I want to do with it?
Your options are these:
With vector (recommended):
With array (not really recommended because of possible exception safety issues):