Urgent :decrement of read-only location

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 16
Reputation: aomran is an unknown quantity at this point 
Solved Threads: 0
aomran aomran is offline Offline
Newbie Poster

Urgent :decrement of read-only location

 
0
  #1
Sep 23rd, 2009
Hi everyone,

Can anyone tells me what this error means:

error: decrement of read-only location.

thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,452
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Urgent :decrement of read-only location

 
0
  #2
Sep 23rd, 2009
My guess is that it means just what it says.

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
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 16
Reputation: aomran is an unknown quantity at this point 
Solved Threads: 0
aomran aomran is offline Offline
Newbie Poster

Re: Urgent :decrement of read-only location

 
0
  #3
Sep 23rd, 2009
I will post the relevant code shortly, but I need more explanation of what decrement of read only location. location of what and how it has been decremented.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: Urgent :decrement of read-only location

 
0
  #4
Sep 23rd, 2009
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
  1. const int X(40); // set X to 40
  2. X--; // set X to 39 not allowed.

Run time, you may have written:
  1. int *Ptr(10); // intending *Ptr to point to a location 10 but
  2. // actually pointing it to location
  3. // error here:
  4. (*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
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 194
Reputation: necrolin will become famous soon enough necrolin will become famous soon enough 
Solved Threads: 19
necrolin's Avatar
necrolin necrolin is offline Offline
Junior Poster

Re: Urgent :decrement of read-only location

 
0
  #5
Sep 23rd, 2009
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:

  1. int main()
  2. {
  3. const int myVar = 5;
  4. int* j = const_cast<int*>(&myVar);
  5. *j = *j - 1;
  6. cout << *j << ": as you can see it's been decremented to 4.\n";
  7.  
  8. return 0;
  9. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Urgent :decrement of read-only location

 
1
  #6
Sep 23rd, 2009
Or maybe you have a const method and you try to decrement a member variable in this method.
Last edited by jencas; Sep 23rd, 2009 at 5:13 am.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 16
Reputation: aomran is an unknown quantity at this point 
Solved Threads: 0
aomran aomran is offline Offline
Newbie Poster

Re: Urgent :decrement of read-only location

 
0
  #7
Sep 23rd, 2009
I actually got these two messages

dheap.h: In member function ‘void Dheap<Process>::deleteMin() const’:
dheap.h:191: error: decrement of read-only location
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 194
Reputation: necrolin will become famous soon enough necrolin will become famous soon enough 
Solved Threads: 19
necrolin's Avatar
necrolin necrolin is offline Offline
Junior Poster

Re: Urgent :decrement of read-only location

 
0
  #8
Sep 23rd, 2009
The "const" at the end of your first error line is your problem. The member function is declared constant so it won't allow you to make any changes to variables in the function.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 16
Reputation: aomran is an unknown quantity at this point 
Solved Threads: 0
aomran aomran is offline Offline
Newbie Poster

Re: Urgent :decrement of read-only location

 
0
  #9
Sep 24th, 2009
thanks guys it works
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC