Hello, I have a small puzzle I cannot solve.
In my class mnode, I have a private data member
float data;
In the constructor, it is given a value, so no worries. This puzzle is this: how can I return the value of data in the public function
float& mnode::nodeData () const
without changing the prototype of nodeData(). I cannot add a const modifier before the float& and I have to return the value of data.
I hear there is some trick to doing this (it does not preserve polymorphism, or so I hear), but I do not know it.
Anyone who knows this or can figure it out, please post an answer.
In my class mnode, I have a private data member
float data;
In the constructor, it is given a value, so no worries. This puzzle is this: how can I return the value of data in the public function
float& mnode::nodeData () const
without changing the prototype of nodeData(). I cannot add a const modifier before the float& and I have to return the value of data.
I hear there is some trick to doing this (it does not preserve polymorphism, or so I hear), but I do not know it.
Anyone who knows this or can figure it out, please post an answer.
Comment