The Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: object constructors with 0 arguments
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Kevin Murphy

Posts: 112
Registered: 12/7/04
object constructors with 0 arguments
Posted: Apr 26, 2000 1:47 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Suppose I have a constructor called 'myclass(arg1, arg2)', with fields
f1, f2. Mathworks says it should be defined like this:

function obj = myclass(arg1, arg2)
if nargin==0
obj.f1 = ...
obj.f2 = ...
obj = class('obj', 'myclass');
elseif isa(arg1, 'myclass')
obj = arg1;
else
obj = normal constructor stuff
end

The question is: who calls the constructor with 0 or 1 arguments?

I discovered that if you save an object as a .mat file and try to load
it, matlab will call the constructor with 0 args. Why?
What initial values should I use for f1, f2, and when will they be set
properly (i.e., with their old values)?
Is there a way to avoid having to handle the 0/1 case explicitely?

Kevin





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.