-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_override.cpp
More file actions
38 lines (31 loc) · 1.13 KB
/
test_override.cpp
File metadata and controls
38 lines (31 loc) · 1.13 KB
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
#include <jaiscript/jaiscript.hpp>
#include <iostream>
int main() {
try {
auto eng = jai::engine::make();
eng->execute(R"(
class Base {
auto internal() { return 42; }
auto public_method() { return internal() * 2; }
}
class Derived : Base {
auto internal() override { return 99; }
auto public_method() override { return internal() * 3; }
}
)");
std::cout << "Classes defined successfully\n";
auto result = eng->execute("Base b = Derived(); b.public_method();");
std::cout << "Result type: " << static_cast<int>(result.type()) << "\n";
std::cout << "Type info ptr: " << static_cast<void*>(result.get_type_info()) << "\n";
if (result.is_int()) {
std::cout << "Value: " << result.as_int() << "\n";
std::cout << "Expected: 297\n";
} else {
std::cout << "ERROR: Not an int!\n";
}
return 0;
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
return 1;
}
}