我知道如何修复它(请参阅我的解决方案@bottom),但不明白为什么会发生此编译错误,因为在我看来,重命名的属性应该由 Precursor 创建到 default_create 中。为什么不是这样?
NRJ_ENTITY
inherit
ANY
redefine
default_create
end
feature {NONE} -- Initialization
default_create
do
create current_day
create current_month
create current_year
Precursor
end
feature -- Access
current_day,
current_month,
current_year: ENERGY_UNIT
end
NRJ_CONSUMER
inherit
NRJ_ENTITY
end
NRJ_GENERATOR
inherit
NRJ_ENTITY
end
NRJ_GENERATOR_CONSUMER
inherit
NRJ_GENERATOR
rename
current_day as current_day_generation,
current_month as current_month_generation,
current_year as current_year_generation
redefine
default_create
select
current_day_generation,
current_month_generation,
current_year_generation
end
NRJ_CONSUMER
rename
current_day as current_day_consumption,
current_month as current_month_consumption,
current_year as current_year_consumption
redefine
default_create
end
feature {NONE} -- Initialize
default_create
do
Precursor {NRJ_GENERATOR}
Precursor {NRJ_CONSUMER}
end
结尾
错误截图
修复 NRJ_GENERATOR_CONSUMER
default_create
do
create current_day_consumption
create current_month_consumption
create current_year_consumption
Precursor {NRJ_CONSUMER}
Precursor {NRJ_GENERATOR}
end