Even if you allocated storage for 32 std::set , you did not initialize this memory range (that is, the constructor of your std::set not called), so the memory you are trying to use in / access is in entry[0].insert (23) will result in undefined behavior.
Mixing C ++ objects with malloc , and this is usually equivalent (I'm tempted to write “always”), which is considered bad practice.
Instead, go to operator new , which will correctly allocate memory and process the design of your object, and also remember delete memory allocated to free memory back to your system (and make the object really destroyed).
The correct way to do this in C ++
Some answers will contain text saying that you are better off using std::vector<std::set> , although this is actually not the answer to your question, so I will leave you with this example fragment
int main (int argc, char *argv[]) { std::set<int> *entries = new std::set<int> [32]; entries[0].insert (123); delete [] entries; }
source share