The body of copy ctor and op= depend on the way you plan to store your resources: a1 and a2 variables. If you need them to be copied to another class - you should write some function that will make a full copy of your SomeClass object. Another case - you can simply copy pointer value - but then be very careful about the way you use them and especially delete them. The easiest solution to the sharing resources problem would be using some smart pointer, for example boost::shared_ptr or c++11 std::shared_ptr.
So if you plan to copy your resources:
class DerivedClass : public BaseClass {
SomeClass* a1;
Someclass* a2;
public:
// note: do not forget to assign zeroes to your pointers, unless you use some kind of smart pointers
DerivedClass()
:a1(0), a2(0){}
DerivedClass(const DerivedClass& d)
:a1(0), a2(0)
{
*this = d;
}
DerivedClass& operator=(const DerivedClass& d)
{
if (this == &d)
return *this;
delete a1;
a1 = d.a1->clone();
delete a2;
a2 = d.a2->clone();
return *this;
}
//constructors go here
~DerivedClass() { delete a1; delete a2;}
// other functions go here ....
};
You will also need SomeClass's clone() function, which going to copy your objects:
class SomeClass
{
public:
SomeClass* clone() const
{
return new SomeClass();
}
};