I am trying to allocate memory to stl list using malloc. I works fine with new as below:
typedef pair<int, int> iPair; list< pair<int, int> > *adj; adj = new list<iPair> [V]; But throws segmentation fault if I use malloc instead of new.
adj=(list<iPair> *)malloc(sizeof(list<iPair>)*V); Why malloc cannot be used to allocate memory to STL containers?
https://stackoverflow.com/questions/66721814/using-malloc-to-allocate-memory-to-stl-list March 20, 2021 at 08:51PM
没有评论:
发表评论