Reputation: 4807
Traits is a concept used in Scala as well as in C++ (although in C++ it is more of an idiom than a concept integrated into the language). It is not obvious to me how the concepts are related though. What is the relation between Scala and C++ traits?
Upvotes: 6
Views: 540
Reputation: 58770
They're not related at all.
In C++, a traits class is a helper object that tells you something about a type that you can't get from the type name itself. C++ traits are actually more similar to Scala's def foo[A:Manifest]
notation (a feature for which I don't know the proper name.)
Scala's traits are actually a lot more like C++'s multiple inheritance (though they differ in the details). I'm actually quite disappointed that C++'s version of multiple inheritance has the official name "multiple inheritance" (to the exclusion of all of the other variations), because the first sentence of any explanation of Scala's traits should be "Traits are a form of multiple inheritance that ..."
Upvotes: 10