I have an abstract class CArticle and two derived classes CBook and CMagazine. I also have a class CLibrary where i want to add articles. Its members are an int variable to count the articles and a double pointer of CArticle.
I have the following main function:
int main()
{
CLibrary L1;
CArticle *A1=new CBook(1000);
CArticle *A2=new CBook(1001);
CArticle *A3=new CMagazine(1002,3);
CArticle *A4=new CMagazine(1003,6);
CArticle *A5=new CMagazine(1004,8);
L1.addArticle(A1);
L1.addArticle(A2);
L1.addArticle(A3);
L1.print();
}
I can't figure out what type of parameter should my addArticle() function have in order to work for this main. I would like to let the compiler choose if the object passed is a CBook or a CMagazine. Is that possible?