Assign derived class to base class

Viewed 14350

Is it safe to do the following or is it undefined behaviour:

class Base
{
private:
    int a;
};

class Derived : public Base
{
private:
    int b;
};

Base x;
Derived y;
x = y;   // safe?

Do the extra bits in derived classes just get sliced off?

2 Answers
Related