Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
Join Date: Nov 2009
Posts: 62
Explain what is Upcasting-Downcasting in C++

I have just started to study C++ programming language. This is my first interaction with a programming language. And I have also never studied C programming language. Though my faculty is helping me alot to understand this C++ there are certain topics which I am unable to understand easily. One of those topics is Upcasting-Downcasting. Please explain to me what is Upcasting and Downcasting in C++?
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Explain what is Upcasting-Downcasting in C++

C++ permits an Object to be used as an Object to its base type or as its own type. C++ also allows use to use the address of the base type for manipulating the Object. Thus, Upcasting in C++ is defined as the process of selecting object's address which can be a pointer or even a reference and then to treat it as it was the base type's address.
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Explain what is Upcasting-Downcasting in C++

To put into simple words down-casting is just the reverse of up-casting. It is exactly the opposite.
Code:
void myFunction(Animal* A)
{
       	   Dog *D = dynamic_cast<Dog*>(A);
    if(D)
    {
        // we are now allowed to easily use D
    }    
}
This above code will help you to understand down-casting. I too was confused between up-casting and down-casting concept. Down-casting is a bit more difficult to understand as compared to up-casting. C++ is although a very easy programming language.

Last edited by Reegan : 26-11-2009 at 01:33 AM.
Reply With Quote
  #4  
Old 26-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Explain what is Upcasting-Downcasting in C++

Downcasting is defined as the method to cast a reference or a pointer of a Base class in C++ to a Derived Class. To perform this conversion which is termed as Downcasting there is a special explicit cast known as dynamic_cast. It defies the basic rule of Object Oriented concept that states variables of a base class are being always assigned by objects of a derived class.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Explain what is Upcasting-Downcasting in C++"
Thread Thread Starter Forum Replies Last Post
Downcasting in java Lauren Ambrose Software Development 5 10-03-2010 12:33 PM
Explain me about dbx in PHP!! Steyn Software Development 5 07-03-2010 04:50 AM
Explain STL KAMAL60 Software Development 3 10-11-2009 05:35 PM
Explain : dsca.exe Asaph Operating Systems 3 15-06-2009 09:44 PM
What is JAR file? Please explain Athos Software Development 4 02-03-2009 05:57 PM


All times are GMT +5.5. The time now is 11:16 AM.