Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
[C++ Error] _algo.c(151): E2024 Cannot modify a const object
|
The compiler takes you to the following line in _algo.c:
// search_n. Search for __count consecutive copies of __val. |
IDE: C++ Builder 6.0
Compiler: Borland BCC32.EXE version 6.0.10.157
Project type: Console Application
#include <algorithm> |
Remove the const of the int for the number of repeats, by static_casting it in the function call.
#include <string> |
Note that a const_cast does not work. Personally, I would find this more appropriate, but I do not understand why this keeps giving the same error.
The actual problem is in _algo.c. I have made all relevant information strong:
// search_n. Search for __count consecutive copies of __val. |
Because _Integer is a template type, the constness of the __count argument is also taken into account. The local _Integer __n, however, must not be const.
A better solution would be to make __n of non-const __integer type, so the user can write const-correct code.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.