Shawn Curry
10-22-2002, 09:02 AM
I have a long math class which is simply a pointer to a string(for flexible length) and an unsigned long for the strlen() (so i dont have to call the function every time i need it). I'm in the process of reworking it now, and I isolated all the whole number math and set that up as my base class. It overrides the operators so I can use the class like a standard number type. I implemented them as virtual to try and get a feel for polymorphism. The whole number class is solid, and i started work on the integer class, deriving it from the whole numbers class. There's a bunch of stuff I can reuse, so it looks like the best way to go, but my question is:
What do I have to override to explicitly convert one number type to the other?
It would be easy to write, the integer class only introduces one new data member: a boolean sign. I want to be able to cast the integer to a whole number(despite the risk of losing info), and vice-versa.
So is it another constructor or assignment operator or something? I have a virtual assignment op in the base class, and I was hoping that simply by carefully coding the derived operator(in the integer class) it would be able to AT LEAST cast a whole number to an integer, but it doesnt want to do it.
Thanks in advance.
What do I have to override to explicitly convert one number type to the other?
It would be easy to write, the integer class only introduces one new data member: a boolean sign. I want to be able to cast the integer to a whole number(despite the risk of losing info), and vice-versa.
So is it another constructor or assignment operator or something? I have a virtual assignment op in the base class, and I was hoping that simply by carefully coding the derived operator(in the integer class) it would be able to AT LEAST cast a whole number to an integer, but it doesnt want to do it.
Thanks in advance.