I have a type casting question. I saw method 2 in my code and it able to compile (The code is not written by me). Can I know what method2 mean? method 1 is understandable.

class Base  {};
class Derived : Base {};

void main ()
{
    //let say I want to type cast my base to derived
    Base base;  
    Derived derived;

    //method 1:
    derived = (Base) base;
    //method 2:
    derived = (Base&) base;
}

Method 2 or class 2?
Anyway, the class 'Derived' is a subclass of extending the base class 'Base'. So technicaly its like the case of a father and his child..they both share the same dna and traits. So if the child needs blood, the father can easily donate..with the statement

 derived = (Base)base; 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.