A Journey Into Non-Virtual Polymorphism
Rud Merriam | A Journey into Non-Virtual Polymorphism 2 Who Doesn’t Recognize This?? 1990 Borland Turbo C++Cppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 3 Background ● Experience – Medium.com (https://medium.com/@rudmerriam)Cppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 4 Polymorphism ● Greek: “many forms” (Obligatory statement) ● The use of a single variableCppcon 2023 | Rud Merriam | A Journey into Non-Virtual Polymorphism 5 Polymorphic Variables ● Base class pointer to derived class – Virtual functions are not bad! ● Standard Template Library0 码力 | 43 页 | 536.84 KB | 5 月前3Optimizing Away Virtual Functions May Be Pointless
carePhoto by Tech Nick on unsplashSimple benchmark class Base { public: int concrete() const; virtual int virt() const; }; void benchmark(Base *b, size_t num_iterations) { auto start = Clock::now(); virt_duration = end-start;There are interesting technical details and surprising conclusions that virtual functions can be actually faster. Since CPU architectures are mentioned, I'd expect to see deep nt-vs-inheritance-vs-other- ways-performanceDoes it even matter?Conclusions ● The notion that “virtual functions are slower” is flat out wrong. ○ Which is not to say they are faster ○ Some of the suggested0 码力 | 20 页 | 1.19 MB | 5 月前3BehaviorTree.CPP: Task Planning for Robots and Virtual Agents
name, const NodeConfig& config) : SyncActionNode(name, config) {} // You must override this virtual function NodeStatus tick() override { std::cout << "Type: [ApproachEnemy]. Instance:" <<0 码力 | 59 页 | 7.97 MB | 5 月前3C++ Exceptions for Smaller Firmware
output_pin { public: virtual ~output_pin() = default; virtual void level(bool p_high) = 0; }; 2122 class output_pin { public: virtual ~output_pin() = default; virtual void level(bool p_high) not severe ‼ severe 🚨 28class output_pin { public: virtual ~output_pin() = default; virtual status level(bool p_high) = 0; virtual resultlevel() = 0; }; 29 std::expected 30 on GCC ARM 95Things that will NOT be covered here ● Nested exceptions ● Anything other than table based exceptions 96Consider the following 97 struct error {}; void foo() { try { bar(); 0 码力 | 237 页 | 6.74 MB | 5 月前3Class Layout
discussing static data members. Type member (included nested classes) do not affect class layout. Non-virtual member functions have no effect on class layout. However, let’s have a few words about them… 9 8 9Class Layout Copyright © 2020 by Stephen C. Dewhurst and Daniel Saks 3 Non-Virtual Member Functions Non-virtual member functions do not occupy any space in the object and don’t affect data member C. Dewhurst and Daniel Saks Non-Member Equivalent The calling sequence for an n-argument non-virtual member function may be the same as that for an (n+1)-argument free function. Some platforms use0 码力 | 51 页 | 461.37 KB | 5 月前3C++ Under the Hood
Construction 10C++ Under the Hood – Inheritance Hierarchy 11C++ Under the Hood – __v_table_ptr 1213 C++ Under the Hood – __v_table_ptr / v_tableC++ Under the Hood – C’tor (Constructor Implementation) 14C++ Under Under the Hood – Construction (construct members)25 C++ Under the Hood – Construction (set this v_table)26 C++ Under the Hood – Polymorphism During Construction27 C++ Under the Hood – Polymorphism During Under the Hood – Construction (construct members)33 C++ Under the Hood – Construction (set this v_table)34 C++ Under the Hood – Polymorphism During Construction35 C++ Under the Hood – Construction360 码力 | 168 页 | 13.55 MB | 5 月前3Modern C++ Tutorial: C++11/14/17/20 On the Fly
constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Explicit virtual function overwrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 override . modern C++ (before the 2020s). Readers can choose interesting content according to the following table of contents to learn and quickly familiarize themselves with the new features that are available such as ordinary arrays, PODs (Plain Old Data, i.e. classes without constructs, destructors, and virtual functions) Or struct type can be initialized with {}, which is what we call the initialization list0 码力 | 92 页 | 1.79 MB | 1 年前3Conan 1.3 Documentation
variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 9.6 Virtual Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . is also the option to generate a table for all binaries from a given recipe with the --table option, even in remotes: $ conan search zlib/1.2.11@conan/stable --table=file.html -r=conan-center $ file.html runtimes for all Operating Systems, platforms and targets There are different approaches: 8.1.1 Using virtual environments We can crate a package that contains an executable, for example from the default package0 码力 | 397 页 | 2.77 MB | 1 年前3Conan 1.4 Documentation
variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 10.6 Virtual Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . is also the option to generate a table for all binaries from a given recipe with the --table option, even in remotes: $ conan search zlib/1.2.11@conan/stable --table=file.html -r=conan-center $ file.html runtimes for all Operating Systems, platforms and targets There are different approaches: 9.1.1 Using virtual environments We can crate a package that contains an executable, for example from the default package0 码力 | 421 页 | 2.84 MB | 1 年前3Conan 1.5 Documentation
variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 10.6 Virtual Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . is also the option to generate a table for all binaries from a given recipe with the --table option, even in remotes: $ conan search zlib/1.2.11@conan/stable --table=file.html -r=conan-center $ file.html runtimes for all Operating Systems, platforms and targets There are different approaches: 9.1.1 Using virtual environments We can create a package that contains an executable, for example from the default package0 码力 | 422 页 | 2.85 MB | 1 年前3
共 226 条
- 1
- 2
- 3
- 4
- 5
- 6
- 23