changeset 468:13362cf4dd89 feature/sublassable_cellarray

Make the overloaded methods call the subclass constructor
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 01 Aug 2017 12:41:42 +0200
parents 8d3c3da3a589
children 365fcdbb8736
files Cell.m callConstructor.m
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r 8d3c3da3a589 -r 13362cf4dd89 Cell.m
--- a/Cell.m	Tue Aug 01 09:28:10 2017 +0200
+++ b/Cell.m	Tue Aug 01 12:41:42 2017 +0200
@@ -30,7 +30,7 @@
         function A = subsasgn(A, S, B)
             disp(S);
             a = subsasgn(A.data, S, B);
-            A = Cell(a);
+            A = callConstructor(A, a);
         end
 
         function B = subsref(A, S)
@@ -47,7 +47,7 @@
             end
 
             c = horzcat(dataArray{:});
-            C = Cell(c);
+            C = callConstructor(varargin{1}, c);
         end
 
         function vertcat(varargin)
@@ -58,7 +58,7 @@
             end
 
             c = vertcat(dataArray{:});
-            C = Cell(c);
+            C = callConstructor(varargin{1}, c);
         end
     end
-end
\ No newline at end of file
+end
diff -r 8d3c3da3a589 -r 13362cf4dd89 callConstructor.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/callConstructor.m	Tue Aug 01 12:41:42 2017 +0200
@@ -0,0 +1,7 @@
+% Calls the constructor of an object.
+% Might be usefull to call the constructor of a subclass object in the superclass
+function obj = callConstructor(subclassObj, varargin)
+    varargin
+    fun = str2func(class(subclassObj));
+    obj = fun(varargin{:});
+end