How to fix a segmentation fault: 11 in c++?
问题 I am currently working on a program that takes the mode from an array of numbers using a template function. The code will compile with no problems using g++ on my macOS (i.e. no errors, warnings, etc.). However when I run the code I get this output in the terminal: Segmentation fault: 11 Here is the code that I have: #include <stdexcept> #include <cstdio> #include <cstddef> template<typename T> T mode(const T* values, size_t length) { if (length < 0) throw std::out_of_range{ 0 }; T result{};