This is because you are not copying instances, but pointers. Infact, you are losing the pointer to one of your instances.
adapter* p = new adapter;
// translates to:
// void* ptr = alloc(sizeof(adapter));
// adapter* p = (adapter*)ptr;
// new (p) adapter(); // invoke the object's ctor.
adapter* q = new adapter;
// that allocated a new adapter on the heap and ctor'd it.
adapter x;
// this created an actual instance of adapter on the stack;
// when 'x' goes out of scope, because it's on the stack,
// it will be destroyed and it's destructor invoked.
adapter y;
// again, on the stack.
p = q;
// that copied the address of the second allocation into
// the first pointer, *losing* the first pointer. C++ does
// not have garbage collection, so this is called a leak.
x = y; // error: tried to use copy operator.
// this attempts to copy the instance "y" to the instance "x".
In addition to this, you also need to get the right fingerprint for the copy operator and ctor:
private:
adapter& operator=(const adapter&);
adapter(const adapter&);
See: http://ideone.com/K4rQdx
class adapter
{
private:
adapter& operator= (const adapter& j);
adapter(const adapter&);
public:
adapter()
{}
};
int main()
{
adapter* p = new adapter;
adapter* q = new adapter;
*p = *q;
return 0;
}
If you want to prevent copying of pointers, you'll need to create a class to encapsulate them, or you'll want to look at std::unique_ptr.
Edit:
Prior to C++11 the normal pattern for "disabling" an operator is to leave it undefined:
private:
adapter& operator = (const adapter&); // name the parameter or not, it's optional.
If someone tries to use it from outside the class, you'll get a compile time privacy error. If something inside the class tries to use it, you'll get a linker error (which is fine when you're expecting it but a headache when you're in crunch trying to fix a release-postponing issue and it's complaining about an undefined function).
With C++11 you can mark it as deleted, which will result in more specific errors:
public:
adapter& operator = (const adapter&) = delete;
I've taken to making these public because some of the compiler versions I work with check the visibility first leading to old-style errors, whereas making it public allows them to reach the "hey, this is disabled" and give you the newer, more helpful errors they have when they encounter a delete'd function/operator.