Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you're looking at it backwards.</p> <p>Nobody sat down and said "OK, we need slicing in this language." Slicing in itself isn't a language feature; it's the name of what happens when you meant to use objects polymorphically but instead went wrong and copied them. You might say that it's the name of a programmer bug.</p> <p>That objects can be copied "statically" is a fundamental feature of C++ and C, and you wouldn't be able to do much otherwise.</p> <p>Edit: [by Jerry Coffin (hopefully Tomalak will forgive my hijacking his answer a bit)]. Most of what I'm adding is along the same lines, but a bit more directly from the source. The one exception (as you'll see) is that, strangely enough, somebody <em>did</em> actually say "we need slicing in this language." Bjarne talks a bit about slicing in <em>The Design and Evolution of C++</em> (§11.4.4). Among other things he says:</p> <blockquote> <p>I'm leery of slicing from a practical point of view, but I don't see any way of preventing it except by adding a very special rule. Also, at the time, I had an independent request for exactly these "slicing semantics" from Ravi Sethi who wanted it from a theoretical and pedagogical point of view: Unless you can assign an object of a derived class to an object of its public base class, then that would be the only point in C++ where a derived object can't be used in place of a base object.</p> </blockquote> <p>I'd note that Ravi Sethi is one of the authors of the dragon book (among many other things), so regardless of whether you agree with him, I think it's easy to understand where his opinion about language design would carry a fair amount of weight.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload