1

I was writing some simple C++ code using DevC++ when this error came up:

I have no clue as to why I am getting this upon initialising a vector array (a graph adjacency list). I couldn't co much to solve this problem since I am not an expert in c++ compilers. I tried reinstalling the program but that didn't help at all.

My compiler is TDM-GCC and in the compiler options I added "-std=c++11", which is executed when calling the compiler.

11
  • You broke the compiler. Time to upgrade it.
    – Botje
    Sep 1, 2020 at 13:39
  • @Botje What do you mean by that :) ? Do you suggest I should uninstall it and install a new one?
    – StLuke5
    Sep 1, 2020 at 13:41
  • The Dev-C++ environment and the compiler supplied with it is very much out of date. There are other more modern and up-to-date environments that are freely available (for example Code::Blocks), as well as distributions of GCC that are also much more modern (for example MinGW). Sep 1, 2020 at 13:42
  • 1
    It appears your compiler is not happy creating an array of size 100M containing std::vector<int> objects.
    – Botje
    Sep 1, 2020 at 13:43
  • Do you need so large array? I suggest you should rethink the algorithm.
    – MikeCAT
    Sep 1, 2020 at 13:43

2 Answers 2

3

This line

std::vector<int> adj[NK];

defines an array of 100 million std::vector objects, along with a static initializer to create all of them.

Did you mean to create a single vector of size 100M?

std::vector<int> adj(NK);
2
  • Actually, that was a mistype. I wanted a vector array like this : vector<int> adj[N]; However, I have just found the solution to my problem and I am going to post it soon
    – StLuke5
    Sep 1, 2020 at 13:48
  • Should probably just use a vector<vector<int>> instead.
    – Botje
    Sep 1, 2020 at 13:49
0

Despite the fact that I made a mistake in the code, it still compiled successfully after a very simple fix. The compiler used to be a 64-bit Release version. I changed the field to the 32-bit Release and the problem disappeared, despite the ridiculous amount of memory my program had needed.

enter image description here

Please note that your mileage may vary and this solution might have some side effects I am not aware of. However, this worked just fine for me and it seems that all my other c++ files compile without any errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.