Your needs objects. Don't just copy pointers. I'll save the "you should be using smart pointers for this" speech, since any time spent on this site will leave you with that tattooed on your eyelids in short-order (and you should, btw use smart pointers =P)
class Foo
{
public:
Foo() : _ordinaryClass(new ordinaryClass())
{
}
virtual ~Foo()
{
delete _ordinaryClass;
}
Foo(const Foo &obj) : _ordinaryClass(new ordinaryClass(*obj._ordinaryClass))
{
}
// copy/swap idiom for assignment. the value-parameter is
// intentional. think about what it does (hint: copy-ctor)
Foo& operator=(Foo other)
{
this->swap(other);
return *this;
}
private:
ordinaryClass *_ordinaryClass;
// they get our cruft, we get theirs.
void swap(Foo& other)
{
std::swap(_ordinaryClass, other._ordinaryClass);
}
};
I would seriously reconsider whether that member should be dynamic in the first place, btw.