Skip to content

Instantly share code, notes, and snippets.

@andyjsbell
Created July 15, 2020 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjsbell/bca6a5317802adf24acffdd76166ea84 to your computer and use it in GitHub Desktop.
Save andyjsbell/bca6a5317802adf24acffdd76166ea84 to your computer and use it in GitHub Desktop.
use cpp::cpp;
use cpp::cpp_class;
cpp!{{
#include <iostream>
class Test {
public:
void method() {
std::cout << "method called" << std::endl;
methodImpl();
}
protected:
virtual void methodImpl() {
std::cout << "methodImpl called" << std::endl;
}
};
}}
cpp!{{
class TestImpl : public Test {
protected:
virtual void methodImpl() override {
std::cout << "methodImpl override called" << std::endl;
rust!(My_Rust_MethodImpl [] {
println!("hey there!");
});
}
};
}}
cpp_class!(pub unsafe struct TestImpl as "TestImpl");
impl TestImpl {
fn new() -> Self {
unsafe { cpp!([] -> TestImpl as "TestImpl" { return TestImpl(); }) }
}
fn run(&self) {
unsafe {
cpp!([self as "TestImpl*"] {
self->method();
})
}
}
}
fn main() {
let t = TestImpl::new();
t.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment