I am working on a code where I need to pass the object of derived(child) class as a parameter into a function of base(Parent) class. I have studied lot of questions already asked, but all of them are giving the solution using pointers. (Some of them are following)
Passing derived class to base function
Passing object of derived class to base class
cast a pointer to member function in derived class to a pointer to abstract member function
Base Class reference to Pointer of Derived Class
But I wanted to ask if there is any way to do this without using the pointers or references. Here is my code. Kindly guide me in the above-mentioned context.
class parent;
class child;
class parent{
public:
void demo(child c)
{
cout<<"Parent"<<endl;
}
};
class child:public parent{
public:
void demoChild()
{
cout<<"Child"<<endl;
}
};
int main()
{
parent p;
child c;
p.demo(c);
c.demo(c);
return 0;
}