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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Can a C++ class have an object of self type?
- Difference between Base class and Derived class in C++
- std::any Class in C++
- std:: valarray class in C++
- std::hash class in C++ STL
- std::uniform_int_distribution class in C++
- std::string class in C++
- Array class in C++
- Structure vs class in C++
- Difference between namespace and class
- How can we write main as a class in C++?
- C++ string class and its applications
- Virtual base class in C++
- Friend class and function in C++
- How to implement our own Vector Class in C++?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.