Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen S is a trivial subclass of T, is it safe to use an array of S where an array of T is expected?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COFor whoever you may trust' sake, this question was asked in my test yesterday. I was fully lost then, and I'm still fully lost about this question now. (The question addressed the assignment of a vector of inherited classes to a vector of base classes in java. It was said there would be a break on the soundness of the operations after the assignment. The assignemnt: `class Mammal ...; class Dog extends Mammal ...; Dog x[] = new Dog[5]; Mammal y[] = x;`).
      singulars
    2. CO@Rubens Java is a very different matter from C++ though. For starters, concerns about the size of the elements (as in the last paragraph of this question) don't apply because all classes are reference types. The soundness problem is visible in code like `y[0] = new Cat; Dog fido = x[0];` would result in the dog `fido` actually being a `Cat`. (This does not actually work, the `y[0] = new Cat` part throws an exception at run time.) *This* problem does apply to C++, but let's assume we're not doing that.
      singulars
      1. This table or related slice is empty.
    3. COI think [this](http://stackoverflow.com/questions/17845128/struct-alignment-c-c]) question gets us some of the way in showing this is OK.
      singulars
 

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