Thread OOP Verständnisproblem! (22 answers)
Opened by kolibri250 at 2019-01-20 00:13

Linuxer
 2019-01-20 12:10
#189487 #189487
User since
2006-01-27
3875 Artikel
HausmeisterIn

user image
Was hast Du probiert? Was heisst "scheint nicht zu funktionieren"?

Der Aufruf einer Methode einer Klasse aus einer anderen Methode dieser Klasse heraus sollte problemlos klappen.

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/perl
use strict;
use warnings;
use 5.010;


package Foo;

sub new {
        my $class = shift;
        my $self = {};

        bless $self,ref($class)||$class;

        return $self;
}


sub foo {
        my $self = shift;

        say "I am foo() calling bar().";
        $self->bar();
}



sub bar {
        my $self = shift;

        say "I am bar().";
}



package main;


my $example = Foo->new();

$example->foo();


Resultat:

Code: (dl )
1
2
I am foo() calling bar().
I am bar().
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread OOP Verständnisproblem!