jeudi 20 octobre 2022

c++ explicit referencing and upcasting [closed]

I know, in c++, I can get the reference of an object by saying

A a{12};
A &ra = a;

To make this a little explicit I can say

A a{12};
A &ra = (A&)a;

But what does the following do?

A a{12};
(A)a;

Imagine I have a class hierarchy

Base base{ /* */}
Derived derived : public Base{ /* */}

Derived dd;
Base &bb = dd; // I know this is okay
// Base &bb = (Base&) dd; // I can use this one to make it explicit but
// Base &bb = (Base)dd; // what's up with that?

Aucun commentaire:

Enregistrer un commentaire