class Base{};
class Derived: public Base{};
int main()
{
Base B;
Derived D;
Base B1 = D;//OK
Derived D1 = B;//error: conversion from ‘Base’ to non-scalar
//type ‘Derived’ requested
return 1;
}
I know derived class has a is-a relationship with base class.
What stops the Derived D1 having values from B and remaining member variables(if any) with some garbage value?
Or
What does the error message
conversion from ‘Base’ to non-scalar type ‘Derived’ requested Derived D1 = B;
say? What is a scalar type?