mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-01-20 05:33:38 +08:00
As discussed in #320. The adds a documentation block that mentions that the trampoline classes must provide overrides for both the classes' own virtual methods *and* any inherited virtual methods. It also provides a templated solution to avoiding method duplication. The example includes a third method (only mentioned in the "see also" section of the documentation addition), using multiple inheritance. While this approach works, and avoids code generation in deep hierarchies, it is intrusive by requiring that the wrapped classes use virtual inheritance, which itself is more instrusive if any of the virtual base classes need anything other than default constructors. As per the discussion in #320, it is kept as an example, but not suggested in the documentation.
116 lines
1.5 KiB
Plaintext
116 lines
1.5 KiB
Plaintext
Constructing ExampleVirt..
|
|
Original implementation of ExampleVirt::run(state=10, value=20)
|
|
30
|
|
Caught expected exception: Tried to call pure virtual function "ExampleVirt::pure_virtual"
|
|
Constructing ExampleVirt..
|
|
ExtendedExampleVirt::run(20), calling parent..
|
|
Original implementation of ExampleVirt::run(state=11, value=21)
|
|
32
|
|
ExtendedExampleVirt::run_bool()
|
|
False
|
|
ExtendedExampleVirt::pure_virtual(): Hello world
|
|
|
|
VI_AR:
|
|
hihihi
|
|
Unlucky = 99
|
|
|
|
VI_AMI:
|
|
hihihihihihi
|
|
Unlucky = 990
|
|
|
|
VI_AT:
|
|
hihihi
|
|
Unlucky = 999
|
|
|
|
B_Repeat:
|
|
B says hi 3 times
|
|
Unlucky = 13
|
|
Lucky = 7.00
|
|
|
|
B_MI:
|
|
B says hi 3 times
|
|
Unlucky = 13
|
|
Lucky = 7.00
|
|
|
|
B_Tpl:
|
|
B says hi 3 times
|
|
Unlucky = 13
|
|
Lucky = 7.00
|
|
|
|
C_Repeat:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
C_MI:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
C_Tpl:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
VI_CR:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 889.25
|
|
|
|
VI_CMI:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 1.75
|
|
|
|
VI_CT:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
VI_CCR:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 8892.50
|
|
|
|
VI_CCMI:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 175.00
|
|
|
|
VI_CCT:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888000.00
|
|
|
|
D_Repeat:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
D_MI:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
D_Tpl:
|
|
B says hi 3 times
|
|
Unlucky = 4444
|
|
Lucky = 888.00
|
|
|
|
VI_DR:
|
|
B says hi 3 times
|
|
Unlucky = 123
|
|
Lucky = 42.00
|
|
|
|
VI_DMI:
|
|
B says hi 3 times
|
|
Unlucky = 1230
|
|
Lucky = -9.50
|
|
|
|
VI_DT:
|
|
VI_DT says: quack quack quack
|
|
Unlucky = 1234
|
|
Lucky = -4.25
|
|
Destructing ExampleVirt..
|
|
Destructing ExampleVirt..
|