CppCon 2014 has ended
Back To Schedule
Monday, September 8 • 8:30pm - 9:15pm

Log in to save this to your schedule, view media, leave feedback and see who's attending!

"Inheritance is the base class of evil" - Sean Parent
Roger, copy that! But sometimes I really want my classes to "import" data members or functions which are better organized elsewhere. And I can do a lot with single inheritance, multiple inheritance, variadic inheritance. Awesome. But when I want to be decent and use composition?
  • I have to know how many members I want to add in advance. There is no variadic composition.
  • I have to decide on the names of those members in advance. There is no compile time way of choosing a name.
  • And if I want my class to offer methods of those members, I have to write forwarding functions and need to know the name of those methods in advance. If the interface of the member changes, my forwarding functions are likely to be broken.
Composition is quite limited when compared to inheritance. That's why we use inheritance so much, especially with templates.

I'll give a few examples, including a real-life case of variadic CRTP and an inheritance-based way of how to specify the names of your data members via template parameters. After that, I'll open the discussion by suggesting two conceptually simple language features and how they could improve our life:
  • Mixin classes
  • Name providers (still looking for a better name).

avatar for Roland Bock

Roland Bock

Principal Software Engineer, PPRO Financial Ltd
From my days at the university, I hold a PHD in physics (although that was in the previous century and seems like a different life by now). Ever since then I have been developing software and/or managing engineering teams. In 2008, I started to learn C++ because I could not believe... Read More →

Monday September 8, 2014 8:30pm - 9:15pm PDT

Attendees (0)