top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C++ : How a programmer can define overloaded type casting operator ?

+2 votes
376 views
C++ : How a programmer can define overloaded type casting operator ?
posted Sep 11, 2016 by Neelam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

It is very simple, use the following definition:

operator () { return }

Here, desired type can be built-in data type or user defined data type.
For example: Assume you have two classes one if known as rupee and the other one is paisa.
rupee rupeeObject(5);
paisa paisaObject(rupeeObject); /* This will not work unless you have overloaded type casting operator for paisa class in rupee class.

answer Sep 16, 2016 by Vimal Kumar Mishra
Similar Questions
0 votes

While doing design for a software, what things enforce to use template classes and template functions ?
Is it consider best practices or not ?

+2 votes

I know the definition of singleton class i.e. a class for which only one object can be defined or initialized. But I want to know all the possible ways to achieve this restriction.

...