[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passed by reference for an octave_value type storing an
From: |
c. |
Subject: |
Re: Passed by reference for an octave_value type storing an |
Date: |
Mon, 12 Nov 2012 16:39:04 +0100 |
On 12 Nov 2012, at 15:16, Olaf Till wrote:
> Without casting away const you cannot change the referenced
> value. Without changing the referenced value, this technique is not
> applicable to the issue I described. The issue is that pass by
> reference is used to change an octave_value to make it keeping track
> of the state (open/closed) of a resource (descriptor).
>
> Olaf
Not sure your reasoning is correct here ...
if you have
const myobject &mo;
and the field "str" in the class "myobject" is a pointer,
then, as you say, you cannot change the pointer "mo.str".
But you can still access the memory pointed to by it, i.e.
you can change "*(mo.str)". [*]
Now what is the type of your "descriptor"? Is it a pointer?
c.
[*] For example, try to compile the example I referred to in the previous
message
and then run the following:
>> autoload ("myobject_init", canonicalize_file_name("myobject.oct"));
>> autoload ("myobject_set_str", canonicalize_file_name("myobject.oct"))
>> mo = myobject_init ("ciao", 12, pi)
>> mo
>> myobject_set_str (mo, "hello!")
>> mo
then look at the code for the DLD function "myobject_set_str" in myobject.cc