Feb 2, 2012 at 3:25pm UTC
class firstclass
{
firstclass& returnplusclass(Secondclass second)
{
//plus logic goes here
return *this;
}
};
class secondclass
{
secondclass& returnplusclass(Firstclass first)
{
//plus logic goes here
return *this;
}
};
Problem is the first class annot use the second's class defintion.
How can I solve this problem, as both classes must pass each other as arguments.
Feb 2, 2012 at 3:28pm UTC
The classes don't actually need each other; the function just needs both. I suggest declaring it globally with two arguments:
firstclass returnplusclass(Firstclass first, Secondclass second) { ... }
Feb 2, 2012 at 3:34pm UTC
Or you can pass by reference and use forward declaration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
class secondclass;
class firstclass
{
firstclass& returnplusclass(const secondclass& second);
};
class secondclass
{
secondclass& returnplusclass(const firstclass& first);
};
firstclass& firstclass::returnplusclass(const secondclass& second)
{
//plus logic goes here
return *this ;
}
secondclass& secondclass::returnplusclass(const firstclass& first)
{
//plus logic goes here
return *this ;
}
Last edited on Feb 2, 2012 at 3:35pm UTC
Feb 2, 2012 at 7:03pm UTC
The forward declartion solved my problem. Thank you.