gshankar
asked on
operator overloading in Constructors
How do I use operator overloading in a Constructor ?
Pl. explain me with an example .
thanx.
Pl. explain me with an example .
thanx.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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);
}
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);
}
ASKER
Yes . Iam convinced with YuraPhink's clue.
That cleared my doubt.
Thanks.
That cleared my doubt.
Thanks.
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).