help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating another object of a given class


From: Jaroslav Hajek
Subject: Re: creating another object of a given class
Date: Mon, 27 Dec 2010 10:47:41 +0100

On Thu, Dec 23, 2010 at 12:11 AM, Steve White <address@hidden> wrote:
>
> What is the best way to create another object of a given class?
>
> Say a function takes an object as an argument
> and a new object of that class is needed.
>
> One way to do it (for an object 'obj') is
>
>     name = class (obj);
>     new_obj = feval (name, args);
>
> However, the Coding-Tips documentation entry says to avoid calling
> feval "excessively":
> http://www.gnu.org/software/octave/doc/interpreter/Coding-Tips.html#Coding-Tips
>
> Another option would be to attach a function handle to the
> constructor of each class as an object member, and call that
> when needed.  But this seems cludgy.
>
> Is there a better/faster/accepted way to do this?
>

Oh no, this is entirely OK. You can interpret that advice as "use
handles where possible and call the directly if possible". There is
little to worry here, however. Besides, the classes internals are not
remotely that tightly optimized to make name lookup a bottleneck :-/


reply via email to

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