If for some reason you want to be able to pass a pointer to operator=, I would suggest creating a different function instead (e.g. CopyFromPointer(Object*)). Of course, I see no reason why you'd need to do that, except maybe if you wanted to allow the caller to pass in a null pointer, but even then I don't know if that would be a good design. So in my opinion, operator=(Object*) is not a good idea.
Also, any reason you have for creating an operator= will probably also be a good reason to create a copy constructor. So if you do one you'll probably do the other (and often times you want to implement the operator= in terms of the copy constructor and a swap() function).
Of course, you don't always need an operator=/copy constructor. Whether you should define your own operator= in a class or not depends on the data in that class. For example, in the following code, the first class does not require an operator=, but the second one does:
Code:
class NoOpEqNeeded
{
public:
NoOpEqNeeded(double newVal, const char* newName) : value(newVal), name(newName), index(0) { }
private:
double value;
std::string name;
int index;
std::list<int> savedDigits;
};
class OpEqNeeded
{
public:
OpEqNeeded(double newVal, const char* newName) : value(new double(newVal))
{
name = new char[strlen(newName) + 1];
strcpy(name, newName);
}
~OpEqNeeded() { delete value; delete name; }
private:
double* value;
char* name;
};
The reason is that the second one has allocated memory stored as a pointer. If you don't add your own operator=, and you try Obj2 = Obj1, then value and name in Obj2 point to the same memory as value and name in Obj1. When their destructors are called, you will likely get a crash, because that memory will be deleted twice.
On the other hand, the data in the first class is either POD types (e.g. int, double, char, float) or classes that already have their own operator= and copy constructor defined (like string and list). Because of that, you don't have to worry about writing your own, because the default one will work perfectly.
Also notice how the first class doesn't need a destructor, but the second class does. The general rule is that if you need a destructor, then you will very likely need a copy constructor and an operator=, so the following three functions come together.
~Object();
Object(const Object&);
const Object& operator=(const Object&);
Slight changes to those prototypes can be made if necessary, depending on your situation, but I think those are the normal forms.