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

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

[Octave-bug-tracker] [bug #59590] arguments not passed to indirectly inh


From: Ray Zimmerman
Subject: [Octave-bug-tracker] [bug #59590] arguments not passed to indirectly inherited constructor
Date: Tue, 1 Dec 2020 17:07:06 -0500 (EST)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15

URL:
  <https://savannah.gnu.org/bugs/?59590>

                 Summary: arguments not passed to indirectly inherited
constructor
                 Project: GNU Octave
            Submitted by: rdzman
            Submitted on: Tue 01 Dec 2020 10:07:04 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: 6.0.90
         Discussion Lock: Any
        Operating System: Mac OS

    _______________________________________________________

Details:

Suppose we have the following set of classdef classes, whre *classC* inherits
from *classB* which in turn inherits from *classA*. The constructor for
*classC* calls its parent with the same arguments, but the intermediate
*classB* does not have an explicit constructor. In this case, arguments passed
to the constructor for *classC* will not be passed to the constructor for
*classA* in Octave, though they are in Matlab.


classdef classA < handle
    methods
        function obj = classA(varargin)
            fprintf('--> classA() called with %d args\n', nargin);
        end
    end
end



classdef classB < classA
end



classdef classC < classB
    methods
        function obj = classC(varargin)
            fprintf('--> classC() called with %d args\n', nargin);
            obj@classB(varargin{:});
        end
    end
end


The result in Octave is ...

> c = classC(1,2,3);
--> classC() called with 3 args
--> classA() called with 0 args


The result in Matlab R2018a (9.4) and later is ...

>> c = classC(1,2,3);
--> classC() called with 3 args
--> classA() called with 3 args


I should note that in Matlab R2017b (9.3) and earlier, this results in an
error ...

>> c = classC(1,2,3);
--> classC() called with 3 args
Error using classB
Too many input arguments.

Error in classC (line 5)
            obj@classB(varargin{:});


My current workaround is to avoid calling constructors that are not explicitly
defined, either by including an explicit constructor in intermediate classes,
e.g. *classB*, or by having the *classC* constructor call the *classA*
constructor explicitly.




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59590>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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