octave-maintainers
[Top][All Lists]
Advanced

[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 17:18:35 +0100

On 12 Nov 2012, at 16:39, c. wrote:

> 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)".

In other words, the following works:

const myobject mo  (static_cast<const myobject&> (args(0).get_rep ()));
*(mo.p_str) = str;

while this version:

const myobject mo  (static_cast<const myobject&> (args(0).get_rep ()));
mo.p_str = new std::string (str);

gives a compile error:

$ mkoctfile -I. myobject.cc 
myobject.cc: In function ‘octave_value_list Fmyobject_set_str(const 
octave_value_list&, int)’:
myobject.cc:103: error: assignment of data-member ‘myobject::p_str’ in 
read-only structure

c.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]