| | |
Urgent :decrement of read-only location
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
My guess is that it means just what it says.
Do you suppose you could post relevant code or some sort of context?
Do you suppose you could post relevant code or some sort of context?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
well your compile should give a line number.....
What you are not saying is if the error is at run-time or at compile time.
Compile time:
you may have written something like this
Run time, you may have written:
Actually the last error is a little difficult to find, without using the debugger or a lot of print statements.
What you are not saying is if the error is at run-time or at compile time.
Compile time:
you may have written something like this
c++ Syntax (Toggle Plain Text)
const int X(40); // set X to 40 X--; // set X to 39 not allowed.
Run time, you may have written:
c++ Syntax (Toggle Plain Text)
int *Ptr(10); // intending *Ptr to point to a location 10 but // actually pointing it to location // error here: (*Ptr)--; // Maybe you intended to write *Ptr--
Actually the last error is a little difficult to find, without using the debugger or a lot of print statements.
experience is the most expensive way to learn anything
Like the others already stated this error comes from trying to manipulate a constant. This should make you wonder a few things including:
Why am I trying to manipulate a constant? It totally beats the point of making something constant if you're going to decrement it later.
If you have to decrement the constant then why not just remove the const and make it a normal variable?
However, if you really need to do this and there's some logical reason for it then there's always const_cast<>. Take a look at my example:
Why am I trying to manipulate a constant? It totally beats the point of making something constant if you're going to decrement it later.
If you have to decrement the constant then why not just remove the const and make it a normal variable?
However, if you really need to do this and there's some logical reason for it then there's always const_cast<>. Take a look at my example:
C++ Syntax (Toggle Plain Text)
int main() { const int myVar = 5; int* j = const_cast<int*>(&myVar); *j = *j - 1; cout << *j << ": as you can see it's been decremented to 4.\n"; return 0; }
![]() |
Similar Threads
- IIS .NET2 virtual directory not working (ASP.NET)
- urgent help plz read (C++)
- How to get the location of the file? (Java)
- CD/RW and floppy drives will not read or write (Storage)
- Help needed :( (C++)
- Increment a number in an array (C)
- compiler message (C)
- Recursion (Java)
- opening files in classes (C++)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






