Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oop 在Matlab中调用实际类_Oop_Class_Matlab_Extends - Fatal编程技术网

Oop 在Matlab中调用实际类

Oop 在Matlab中调用实际类,oop,class,matlab,extends,Oop,Class,Matlab,Extends,假设我有一门课: classdef abstractGame %UNTITLED Summary of this class goes here % Detailed explanation goes here properties end methods (Abstract, Static) run(gambledAmount); end methods (Static) function ini

假设我有一门课:

classdef abstractGame
    %UNTITLED Summary of this class goes here
    %   Detailed explanation goes here

    properties
    end

    methods (Abstract, Static)
        run(gambledAmount);
    end

    methods (Static)
        function init()
            gambledAmount = validNumberInput(abstractGame.getGambleString(), 1, 100, 'helpText', 'round');
        end
        function str = getGambleString()
            str = 'How much do you want to gamble?';
        end
    end

end
其他类也从这个类扩展而来。我希望子类重新定义getGambleString方法,而init方法使用最深类定义的方法(而不是abstractGame。[…]我希望调用类似calledClass的东西。[…])

我该怎么称呼呢?
提前感谢。

这是一个
静态虚拟
功能问题;然而,即使在C++中,这样的构造也不可能在MATLAB中得到。()

顺便说一句,在matlab中,非静态方法的行为就像虚拟的(在Java中一样),因此,如果您接受不使用静态函数,您可以获得所需的效果

证明(简化代码):

classdef抽象游戏
函数str=init(obj)
str=getstring(obj);
结束
函数str=getstring(obj)
str=‘你想赌多少?’;
结束
结束
结束
classdef游戏
这是一个
静态虚拟
功能问题;然而,即使在C++中,这样的构造也不可能在MATLAB中得到。()

顺便说一句,在matlab中,非静态方法的行为就像虚拟的(在Java中一样),因此,如果您接受不使用静态函数,您可以获得所需的效果

证明(简化代码):

classdef抽象游戏
函数str=init(obj)
str=getstring(obj);
结束
函数str=getstring(obj)
str=‘你想赌多少?’;
结束
结束
结束
classdef游戏
实际上,我认为可以使用Matlab的动态方法进行准虚拟静力学
eval([class(obj)'.getGambleString'])
将在对象的特定类上调用静态getGambleString方法,代价是要求您在每个子类中重新定义该方法,并降低调用速度。并不是说我推荐一个真正做到这一点的人。您的非静态解决方案在实践中更好。实际上,我认为您可以使用Matlab的动态方法进行准虚拟静态
eval([class(obj)'.getGambleString'])
将在对象的特定类上调用静态getGambleString方法,代价是要求您在每个子类中重新定义该方法,并降低调用速度。并不是说我推荐一个真正做到这一点的人。您的非静态解决方案在实践中更好。
classdef abstractGame
  function str = init(obj)
        str = getGambleString(obj);
    end
    function str = getGambleString(obj)
        str = 'How much do you want to gamble?';
    end
  end
end


 classdef game < abstractGame
  methods 

    function str = getGambleString(obj)
        str = 'Hi!';
    end
  end    
 end


d = game;

d.init()

  ans =

   Hi!