Was asked this question in IBM ISL interview. Can I write a copy constructor for an Abstract base class using pointer instead of reference (&)?
I think it can be used. Any comments/suggestions?
#include <string>
//abstract base class
class ABC{
int a;
int b;
char *p;
public:
virtual void f() = 0;
ABC(){};
ABC(ABC* abc){
a = abc->a;
b = abc->b;
p = new char[strlen(abc->p)+1];
p = strcpy(p, abc->p);
}
};
//derived class
class ConcreteDerivedClass: private ABC
{
public:
ConcreteDerivedClass(){}
void f(){}
ConcreteDerivedClass(ConcreteDerivedClass& obj):ABC(&obj){}
};