I'm currently attempting to simplify the use of my 'data-type' (var_var) by overloading operators in relation to it. First, an example of its usage:
Code:
class Test { // The test class.
public: // Only public members for simplicity.
var_var *HP;
var_var *MP;
// functions omitted for clarity.
}
The var_var pointers point to dynamically allocated derived classes of var_var (which, by itself, is of no importance) which are able to hold values of differing sizes. The size of the value held/assigned etc is taken into account and the pointer redirected to a larger/smaller type as needed. To make it simpler to interface with, I have been overloading operators to make syntax such as
Code:
int x = (ob.HP + ob.MP)
useable, as opposed to
Code:
int x = (ob.HP->getval() + ob.MP->getval())
Unfortunately, I am unable to work out how to implement the assignment operator in the following context.
Code:
Test ob; // Assume default initialisation.
ob.HP = 300; // Dereference operator intentionally omitted.
While I know the cause of the error (the assignment operator is overloaded for a var_var and int assignment, while this is a var_var * and int assignment) I do not know how to remedy this while keeping the usage syntax this simple. Because the assignment operator has to be a member of the class, I am unable to make the left operand anything other than the this pointer.
(Yes, I know it may seem strange that I don't want to use the dereference operator, but I'm trying to make this have a similar interface to built-in integers, without using pointing-related operators).
Also, I would prefer answers other than 'change your compiler' (I'm using Borland's free 5.5 version).