Brian Silverman | 4e662aa | 2022-05-11 23:10:19 -0700 | [diff] [blame^] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
| 9 | // This example shows Rust subclasses of C++ classes. |
| 10 | // Here are the C++ classes which we're subclassing. |
| 11 | |
| 12 | #pragma once |
| 13 | |
| 14 | #include <string> |
| 15 | #include <memory> |
| 16 | |
| 17 | class MessageProducer { |
| 18 | public: |
| 19 | virtual std::string get_message() const = 0; |
| 20 | virtual ~MessageProducer() {}; |
| 21 | }; |
| 22 | |
| 23 | class MessageDisplayer { |
| 24 | public: |
| 25 | virtual void display_message(const std::string& message) const = 0; |
| 26 | virtual ~MessageDisplayer() {}; |
| 27 | }; |
| 28 | |
| 29 | void register_cpp_thingies(); |
| 30 | void register_producer(const MessageProducer& producer); |
| 31 | void register_displayer(const MessageDisplayer& displayer); |
| 32 | |
| 33 | void run_demo(); |