Primitive x; // turns x into an int primitive and sets it to 5 x = 5; // gets the dereferenced value of x (which is 5) and prints it to the screen std::cout << x.getValue() << endl;As it is, if I want to print out the number 5 to the screen I need to do this:
std::cout << *(int*)x.getValue() << endl;That assumes I already know that x is an int, which I may or may not know. The source code for my Primitive Class is fairly simple and is as follows:
class Primitive {
public:
Primitive() {
type = -1;
is_protected = false;
}
void operator=(bool newVal) {
value = new bool(newVal);
type = 0;
}
void operator=(char newVal) {
value = new char(newVal);
type = 1;
}
void operator=(short newVal) {
value = new short(newVal);
type = 2;
}
void operator=(int newVal) {
value = new int(newVal);
type = 3;
}
void operator=(long newVal) {
value = new long(newVal);
type = 4;
}
void operator=(float newVal) {
value = new float(newVal);
type = 5;
}
void operator=(double newVal) {
value = new double(newVal);
type = 6;
}
void operator=(CString newVal) {
value = new CString(newVal);
type = 7;
}
void operator=(char* newVal) {
value = new CString(newVal);
type = 7;
}
void* getValue() {
return value;
}
private:
CString name; // name of primitive
bool is_protected; // can the primitive be modified
void* value;
int type;
// 0 bool
// 1 char
// 2 short
// 3 int
// 4 long
// 5 float
// 6 double
// 7 string
};
So to simply my problem... is there a method I can make that automatically dereferences the value stored by the primitive so that I don''t have to dereference it myself?
Any help is appreciated.