Skip to content

Commit 1e199d0

Browse files
committed
Add tests for const dynamic cast
1 parent 54a8f8e commit 1e199d0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

examples/inheritance.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ namespace virtualsolver
180180
};
181181
}
182182

183+
struct Parent {
184+
virtual std::string name() const { return "Parent"; }
185+
virtual ~Parent() = default;
186+
};
187+
188+
struct DerivedA : public Parent {
189+
std::string name() const override { return "DerivedA"; }
190+
};
191+
192+
struct DerivedB : public Parent {
193+
std::string name() const override { return "DerivedB"; }
194+
};
195+
196+
197+
Parent* make_a() { return new DerivedA(); }
198+
Parent* make_b() { return new DerivedB(); }
199+
const Parent* make_const_a() { return new const DerivedA(); }
200+
const Parent* make_const_b() { return new const DerivedB(); }
201+
183202
namespace jlcxx
184203
{
185204
// Needed for upcasting
@@ -196,6 +215,9 @@ namespace jlcxx
196215
template<> struct IsMirroredType<StaticBase> : std::false_type { };
197216
template<> struct IsMirroredType<StaticDerived> : std::false_type { };
198217
template<> struct SuperType<StaticDerived> { typedef StaticBase type; };
218+
219+
template<> struct SuperType<DerivedA> { typedef Parent type; };
220+
template<> struct SuperType<DerivedB> { typedef Parent type; };
199221
}
200222

201223
JLCXX_MODULE define_types_module(jlcxx::Module& types)
@@ -230,6 +252,20 @@ JLCXX_MODULE define_types_module(jlcxx::Module& types)
230252
.constructor<int, double>()
231253
.method("getData", &VirtualCfunctionExtended::getData)
232254
.method("set_callback", &VirtualCfunctionExtended::set_callback);
255+
256+
types.add_type<Parent>("Parent")
257+
.method("name", &Parent::name);
258+
259+
types.add_type<DerivedA>("DerivedA", jlcxx::julia_base_type<Parent>())
260+
.method("name", &DerivedA::name);
261+
262+
types.add_type<DerivedB>("DerivedB", jlcxx::julia_base_type<Parent>())
263+
.method("name", &DerivedB::name);
264+
265+
types.method("make_a", &make_a);
266+
types.method("make_b", &make_b);
267+
types.method("make_const_a", &make_const_a);
268+
types.method("make_const_b", &make_const_b);
233269
}
234270

235271
JLCXX_MODULE define_vsolver_module(jlcxx::Module& vsolver_mod)

0 commit comments

Comments
 (0)