Tuesday, April 5, 2011

Assign derived class to base class

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?

From stackoverflow

0 comments:

Post a Comment