octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50367] Default constructor for objects in arr


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #50367] Default constructor for objects in array
Date: Fri, 3 Mar 2017 06:54:02 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

Update of bug #50367 (project octave):

                Priority:              5 - Normal => 3 - Low                
                  Status:               Need Info => Wont Fix               
             Open/Closed:                    Open => Closed                 
                 Release:                   4.2.0 => dev                    

    _______________________________________________________

Follow-up Comment #4:

I think it is not worth fixing. MATLAB disbands from the `obj = class (obj,
'cname')` syntax in favor of classdef, that works like a charm for you
example, that was flawed by the way:

Legacy class in "@xxx"-folder:

+verbose+
function obj = xxx(in)
  if nargin == 0 
    fprintf('xxx: empty arguments\n');
    obj.str = 'no init';
  else
    fprintf('xxx: argument %d\n', in);
    obj.str = in;
  end
  obj = class(obj, 'xxx');
end % function
-verbose-

Using classdef:

+verbose+
classdef xxx2
  
  properties
    str
  end
  
  methods
    function obj = xxx2(in)
      if nargin == 0
        fprintf('xxx: empty arguments\n');
        obj.str = 'no init';
      else
        fprintf('xxx: argument %d\n', in);
        obj.str = in;
      end
    end
  end
  
end
-verbose-

Octave:

+verbose+
>> a(1,3) = xxx(3)
xxx: argument 3
a =

  <class xxx>
>> a.str
error: invalid index for class
>> b(1,3) = xxx2(3)
xxx: argument 3
xxx: empty arguments
b =

<object array xxx2>

>> b.str
ans = no init
ans = no init
ans =  3
-verbose-

MATLAB R2016b:

+verbose+
>> a(1,3) = xxx(3)
xxx: argument 3
xxx: empty arguments

a = 

        xxx object: 1-by-3

>> a.str
Access to an object's fields is only permitted within its methods.
 
>> b(1,3) = xxx2(3)
xxx: argument 3
xxx: empty arguments

b = 

  1×3 xxx2 array with properties:

    str

>> b.str

ans =

no init


ans =

no init


ans =

     3
-verbose-

Therefore I declare this as "won't fix", as a future save workaround exists
and close this item.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50367>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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