gpt4 book ai didi

perl - 在 Perl 6 中调用类中的私有(private)方法

转载 作者:行者123 更新时间:2023-12-04 23:42:44 25 4
gpt4 key购买 nike

我不能在 Perl 6 的类中调用私有(private)方法:

class MyClass {

method !my-private-method($var1) {
# ....
}

method my-method() {
my $my-var1 = !my-private-method(123); # not found (Undeclared routines)
my $my-var1 = $!my-private-method(123); # not found (Undeclared routines)
my $my-var1 = $.my-private-method(123); # not found (Undeclared routines)
my $my-var1 = my-private-method(123); # not found (Undeclared routines)

那么如何调用 my-private-method来自 my-method ?

最佳答案

您必须在实例对象上调用私有(private)方法。

my $my-var1 = self!my-private-method(123);

应该管用。

关于perl - 在 Perl 6 中调用类中的私有(private)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33029990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com