首页 > 解决方案 > 无法实例化派生的 MATLAB 类而不会出错

问题描述

每当我尝试实例化我的 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

标签: matlababstract-class

解决方案


推荐阅读