Conversion operators are can be used when where you want to use your object in place of some another datatype ....
For example ....
If we have a class called TestClass like
class TestClass
{
bool m_bTestMember;
public:
TestClass()
{
m_bTestMember= false;
}
SetTestMember( bool i_bSet )
{
m_bTestMember=i_bSet;
}
}
int main()
{
TestClass test;
if (test) {
printf("Hurray");
}
else
{
printf("BadLuck");
}
}
Hence to able to use test in if condition you will need to add conversion operator in your class...like follwoing one
class TestClass
{
bool m_bTestMember;
public:
TestClass()
{
m_bTestMember= false;
}
SetTestMember( bool i_bSet )
{
m_bTestMember=i_bSet;
}
operator bool()
{
return m_bTestMember;
}
}
Now you can use object of this class in
IF condition.