-4

if I have a function set up similarly to this:

update_value(const int& old_value, const int& new_value){
}

What if I need to get the value of old_value and new_value and use these values in a mutable variable?

I can't dereference with a *pointer. How do I work around this?

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
Ben361
  • 1
  • Remove the `const` and `&`> – Ed Heal Jul 25 '15 at 05:54
  • 2
    What if you what? And what does dereferencing have to do with this? You seem really, really confused. No offence. – Lightness Races in Orbit Jul 25 '15 at 05:54
  • OK so the method accepts as parameters two const int& variables ie: (const int&old, const int& new){} In this method I need to access elements in array based on these values. Such as Array[old] = Array[new] – Ben361 Jul 25 '15 at 06:02
  • We see what you have. We're clueless as to what you want. `const` means that you don't *want* to modify something. Please click "edit" and put an expression of `old_value` and `new_value` inside the function. – Potatoswatter Jul 25 '15 at 06:04
  • It is part of an assignment where I am stuck with two parameters that are const int&. Using these values I need to access the old value in a heap and update it with the new value. – Ben361 Jul 25 '15 at 06:09
  • Update your question to reflect what your total object is. otherwise is sounds like an XY problem. you can't update new_value in this case (without exploiting some higher level techniques) because it's const. Also, you don't dereference a reference, you use it kinda the same way Java handles objects, except you're dealing with primitives. If you need to use them with an array as you mentioned in comment, update your question to reflect that requirement to clear up some of the confusion. – ydobonebi Jul 25 '15 at 06:32
  • The value of `old_value` and `new_value` *are* `old_value` and `new_value` respectively. – user207421 Jul 25 '15 at 06:49

1 Answers1

0

First of all your question is not so clear and I dont know why you want to use mutable keyword.Mutable keyword can be used only for class member variables.

Regarding your question,in the comment you mentioned that you want to access some index of the array based on the passed arguments.Since you are not changing passed argument value you can directly use your passed argument in the accessing array value.

krish
  • 95
  • 7