![](/img/trans.png)
[英]Eiffel: is there a way to prohibit the use of any particularly inherited creation method?
[英]Eiffel: how do I create and use an UTIL class, or “call static method from class”
正如我的帖子描述的那样,我想创建一个带有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 used in the non-object call is not a class feature.
我看到了两种关于对象创建的符号- {UTIL}.never_both (a, b)
- ({UTIL}).never_both (a, b)
它们之间有什么区别?
如果可能,如何在埃菲尔铁塔中创建一个应用程序对象(如果需要,甚至可以在世界范围内!)以使用此UTIL?
我知道这是个问题,所以我将其加粗
如果要使用功能而不创建相应的对象,则应将其标记为class
功能。 这是在功能后置条件中使用相同的关键字完成的:
foo ...
do
...
ensure
instance_free: class
...
end
之后,可以在无对象调用{BAR}.foo ...
使用该功能。
表示法({BAR}).qux
不表示无对象调用。 这是对TYPE [BAR]
类型的目标对象的对象调用。 对象描述类型BAR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.