A simple scripting language in C++
Ferenc Szontágh
2025-04-19 558e0191ba5a5b0ab99825de7d7d2219387e559e
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
42
43
44
45
46
47
48
class test1 {
 
    private:
    string $name;
    int $age;
 
    public:
    // constructor method, the return is always the class, can not use 'return' keyword here
    function construct(string $name, int $age) {
        this->name = $name;
        this->age = $age;
    }
 
    function getAge() int {
        return this->age;
    }
 
    function getName() string {
        return this->name;
    }
 
    function isAdult() bool {
        return this->age >= 18;
    }
 
    function changeName(string $new_name) {
        this->name = $new_name;
    }
 
    function incrementAge(int $incremental) int {
        return this->age + $incremental;
    }
 
 
}
 
//
 
test1 $testclass = new test1("Batman", 17);
 
if ($testclass->isAdult() == false) {
    printnl($testclass->getName(), " is not adult.. incrementing the age");
    $testclass->incrementAge(1);
}
 
if ($testclass->isAdult()) {
    println($testclass->getName(), " is adult");
}