...

Explicit Class Conversions??

Shawn Curry
10-22-2002, 08: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.

Shawn Curry
10-22-2002, 08:16 AM
Just for a further clarification, I know I could just write a function to do this, I just want to be able to say something like:

Whole a = "100";
Integer b = a;

OR

Integer b(a);// like a copy constructor

I have no problem writing a conversion, I just want to be able to implement it like you can with regular numbers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum