Through class conversion, one can assign data that belongs to a particular class type to an object that belongs to another class type.
Let there be two classes ‘A’ and ‘B’. If we want to allocate the details that belong to class ‘A’ to an object of class ‘B’ then this can be achieved by –
B(object of class B) = A(object of class A)
where ‘=’ has been overloaded for objects of class type ‘B’.
Class conversion can be achieved by conversion function which is done by the use of operator overloading.
- Can a C++ class have an object of self type?
- std::any Class in C++
- Array class in C++
- std::string class in C++
- std:: valarray class in C++
- Structure vs class in C++
- Difference between namespace and class
- Virtual base class in C++
- What all is inherited from parent class in C++?
- Simulating final class in C++
- Why is the size of an empty class not zero in C++?
- Friend class and function in C++
- C++ string class and its applications
- C++ String Class and its Applications | Set 2
- STL Priority Queue for Structure or Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.