Can anyone give example about passing an object of a class as argument to the function of same class.
class Unicorn {
void Eat(Unicorn other_unicorn) {
// implementation omitted to keep this answer family-friendly
}
};
int main() {
Unicorn glitter;
Unicorn dazzle;
glitter.Eat(dazzle); // mmmm, yummy
}
Note that Dazzle is still alright because we made a copy of him and fed the copy to Glitter.
class X
{
public:
void func(X x) {}
};
int main()
{
X a,b;
a.func(b);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With