Link to home
Start Free TrialLog in
Avatar of gshankar
gshankar

asked on

operator overloading in Constructors

How do I use operator overloading in a Constructor ?
Pl. explain me with an example .
thanx.
ASKER CERTIFIED SOLUTION
Avatar of YuraPhink
YuraPhink

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YuraPhink
YuraPhink

OK,
if you mean using operators (which you already defined in the class) in the constructor, then use them as well as in every other function (like in main).
Can u give an example how you want to was in ctor??
Do you mean conversion?

struct A
{
   int i;  
};

struct B
{
   int j;
   B() : j(0) {}
   B(const A& a) : j(a.i) {}
};


void f(const B& b)
{}

void g()
{
   A a;
   f(a);
}
Avatar of gshankar

ASKER

Yes . Iam convinced with YuraPhink's clue.
That cleared my doubt.
Thanks.