如my post描述它,我想创建一个带有 never_both 函数的 UTIL 类。
class
UTIL
create
default_create
feature -- could be in class BOOLEAN
double_implies, reversible_implies, never_both (a, b: BOOLEAN): BOOLEAN
-- Into boolean class with never_with
do
if a and b then
Result := False
else
Result := True
end
end
end
当我使用它时
invariant
never_both: {UTIL}.never_both (attached last_error, attached last_success_message)
编译器提示VUNO
错误
非对象调用中使用的never_both不是类功能。
我看到了 2 个关于对象创建的符号
- {UTIL}.never_both (a, b)
- ({UTIL}).never_both (a, b)
它们有什么区别?
如果可能的话,如何在 Eiffel 中创建一个应用程序范围的对象(如果您愿意,甚至可以是世界范围的对象!) 以便使用此 UTIL?!
我知道这是一个问题元组,所以我把它们用粗体
最佳答案
如果您想使用某个功能而不创建相应的对象,则应将其标记为class
功能。这是在功能后置条件中使用相同的关键字完成的:
foo ...
do
...
ensure
instance_free: class
...
end
之后,该功能可以在无对象调用中使用 {BAR}.foo ...
。
符号({BAR}).qux
并不表示无对象调用。它是对 TYPE [BAR]
类型的目标对象的对象调用。该对象描述了 BAR
类型。
关于createprocess - Eiffel:如何创建和使用 UTIL 类,或 "call static method from class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52778337/