无法实例化派生的MATLAB类而不会出现错误

时间:2019-04-20 21:15:11

标签: matlab abstract-class

每当尝试实例化Pawn类时,都会收到错误消息。 “使用Pawn时出错,无法在类'Pawn'中定义属性'AvailMoves',因为该属性已在超类'ChessPiece'中定义。”

classdef (Abstract) ChessPiece

    properties (Abstract)
        AvailMoves;
        value;
        white;
        position;
        row;
        column;
    end
end

classdef Pawn < ChessPiece

    properties 
         AvailMoves;
         value;
         white;
         position; %position is a 1 by 2 vector with the piece's position on the board
         hasMoved;
         row;
         column;
    end

    methods 
        function obj = Pawn(position,white)
            %UNTITLED3 Construct an instance of this class
            %   Detailed explanation goes here
            obj.hasMoves = false;
            obj.white = white;
            obj.position = position;
            obj.row = position(1);
            obj.column = position(2);
            obj.AvailMoves = {};
            obj.value = 1;
        end
    end
end

0 个答案:

没有答案