help-octave
[Top][All Lists]

Re: octave and oo

 From: John W. Eaton Subject: Re: octave and oo Date: Sun, 14 Nov 2010 13:34:13 -0500

```On 14-Nov-2010, Ernst Reissner wrote:

| Dear John,
|
| OK I tried:
|
| >   function retval = DocPolynom(c)
| >      % Construct a DocPolynom object using the coefficients supplied
| >      if isa(c,'DocPolynom')
| >         obj.coef = c.coef;
| >      else
| >         obj.coef = c(:).';
| >      end
| >      retval = class (obj, 'DocPolynom');
| >   end
| >
| > and it should work.
| >
| and it seems to bring me one step further.
| This time i obtain:
|
| octave:2> c = double(p)
| error: no subsindex method defined for class DocPolynom

It does work for me with 3.2.4 on my Debian system, using Octave from
the Debian package.  Here is what I see:

octave3.2:1>  p = DocPolynom([1 0 -2 -5])
octave3.2:2> class (p)
ans = DocPolynom
octave3.2:3> double (p)
ans =

1   0  -2  -5

octave3.2:4> quit

I have the following functions defined:

@DocPolynom/DocPolynom.m:

function retval = DocPolynom(c)
% Construct a DocPolynom object using the coefficients supplied
if isa(c,'DocPolynom')
obj.coef = c.coef;
else
obj.coef = c(:).';
end
retval = class (obj, 'DocPolynom');
end

@DocPolynom/double.m:

function c = double(obj)
% DocPolynom/Double Converter
c = obj.coef;
end

| Suggestion:
| The example is from site
|
| http://www.mathworks.com/help/techdoc/matlab_oop/f3-28024.html
|
|
| and I think it would be best to rework this site so that the examples
| work as described.

If you are saying that you think the examples on the web page should
be changed, then I don't see how any of us here can help with that
suggestion...

Does the constructor without the call to class () work in Matlab?  If
so, what version?  If it does work in some version of Matlab, then I
guess they have changed the way Matlab handles constructors, because
in the past I think it was required that construtors return class
objects created with the class function.

I suppose it would be possiblbe to detect that a class construtor was
called and that if it is returning a structure, not a class, to
automatically convert the structure to a class.  But if that change
was made in Matlab, I think it is quite recent, I was not aware of it,
and so far, no one has reported the new incompatibility until now.  If
this is the new behavior, then where is it documented?

jwe

```

reply via email to