Hi All

I was going through a code and came across something like -->

TC_A &tc_a=*(TC_A *)p;

Now TC_A is a derived class of another Class 'X' of which p is an instance.
Does this mean that a new class instance of TC_A is invoked and contents of p copied onto it ?

Can i replace it with

TC_A *tc_a = new TC_A;
tc_a=(TC_A)p;

It would be great if someone could help me understand as to what this code actually does.


Best Regards
Varun

No, notice the & sign before tc_a? This means tc_a is a reference.
So tc_a will reference p, which essentially makes them one and the same object.

Have you ever used references in function parameters? If not.. this is a good time to read about it ;)

No, notice the & sign before tc_a? This means tc_a is a reference.
So tc_a will reference p, which essentially makes them one and the same object.

Have you ever used references in function parameters? If not.. this is a good time to read about it ;)

Thanks :) !!

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.