Saving and Loading Objects from Class Hierarchies

  • Follow


Hi,

I am trying to build a class that inherits from another class, in which both classes have the ability to save objects. The superclass code is as follows:

classdef exclass
    properties
        value
    end
    methods
        function obj=exclass(in)
            obj.value=in;
        end
        function [val,obj]=myfun(obj)
            [val,obj]=obj.doubler();
        end
        function [val,obj]=doubler(obj)
            obj.value=obj.value*2;
            val=obj.value;
            fprintf('%d',val);
        end
        function S=saveobj(obj)
            S.Pointvalue=obj.value;
        end
        function obj=reload(obj,S)
            obj.value=S.Pointvalue;
        end
    end
    methods (Static=true)
        function obj=objload(S)
            obj=exclass;
            obj=reload(obj,S);
        end
    end
end

and the subclass code is as follows:

classdef myclass < exclass
    properties
        val
    end
    methods
        function obj=myclass(value,val)
            obj=obj@exclass(value);
            obj.val=val;
        end
        function S=saveobj(obj)
            S=saveobj@exclass(obj);
            S.Pointval=obj.val;
        end
        function obj=reload(obj,S)
            obj=reload@exclass(obj,S);
            obj.val=S.Pointval;
        end
    end
    methods (Static=true)
        function obj=loadobj(S)
            obj=myclass;
            obj=reload(obj,S);
        end
    end
end

While I can save and load the superclass fine, when I try saving and loading the subclass, all of the parameters of the loaded object are empty sets. The error I get is:

Error occurred while trying to load object of type myclass:
Input argument "value" is undefined.

I understand that "value" is undefined, but how do I make a constructor where "value" doesn't need to be defined? Or how do I get a "value" when the myclass constructor doesn't have any inputs?

Thanks,

Eric
0
Reply Eric 6/4/2010 3:10:23 PM


0 Replies
223 Views

(page loaded in 0.001 seconds)

Similiar Articles:








7/5/2012 10:01:28 PM


Reply: