Your only allowed to declare constants in the class definition, but that would be counter productive to your origional goal. Which by the way I see may be out of reach as of yet.
Ok, now I'm at home. A lot of catching up, I see. :-)
Agreed, this is too darn interesting! I have never done it because of its complexity and lack of time! And here I am investing whatever little time I have.
Ok, so there are two mainstreams here: Mine, polymorphic oriented, and Computergeek01's + mcqueen, template oriented. Let's make a small proof of concept:
Let's each write some very basic classes that allow to: Sum two distances: One in in meters and the other one in feet; define a time class that can handle conversion between seconds and hours, and one speed class that can be produced by the division of Distance object by a Time object.
And we can see which model is better. Does it sound OK?
enum
{
feet,
inches,
yard,
};
int FEET = feet; /*Concept on how to deal with different inputs to the constructor*/
int INCH = inches;
int YARD = yard;
template<class Unit>
class Pre
{
public:
Unit Kilo(Unit unit) {return (unit * 1000);} //Examples because my last post about this
Unit Mega(Unit unit) {return (unit * 1000000);} //was a bit scattered
};
template<class D>
class Dist: public Pre<D>
{
private:
D metre;
public:
Dist() {metre = 0;}
Dist(D m) {metre = m;}
Dist(D m, int); /*Defined Later*/
D dist() {return metre;}
D distEN() {return ((D) (metre * 3.2808399));}
D operator+(Dist add)
{Dist<D> d = metre + add.metre;}
};
template<class D>
Dist<D>::Dist(D m, int arg)
{
metre = m;
switch(arg)
{
case feet: metre = (D) metre/3.2808399; break;
case inches: metre = (D) ((metre/12) / 3.2808399); break;
case yard: metre = (D) metre * 1.0936133; break;
}
}
It needs a specilized template for integers because of the unit conversions or else it throws a warning but it works to my satisfaction.
Basically the same as the first but with a few changes in the formula etc. All of the simularities are the kind of stuff I would work toward putting in the Base_Class.
I won't have time to write the third one tonight but I'll get back to you as soon as I can.
Mine aren't that good and I am stupid. I cannot create a working good idea for this project. But some of these ideas are basic and should not need use of class like seconds to hours. It's better not to use class for that function as I did not. Please think harder on your ideas though and the best way to execute them: class, or not with class?
class or not with class???
And as you see not with class can also be shorter as well.
Here's a better idea:
Create a program/library of classes that can calculate miles per gallon instead of distance, how many gallons per mile?
2. Ill tell you tomorrow i've got to go. Please think about what i've said so far. Not to ruin the party ,but with these basicish ideas/traps we are falling into, it isn't that great of a project, SO
Most of this stuff, seconds to hours hours=seconds*60*60,REALLY? BASIC!!! NEED HARD STUFF! I MAY SAY I'M STUPID BUT I'M NOT! JUST FEEL LIKE IT WHEN IM AROUND YOU PEOPLE WHO KNOW MORE THAN THERE'S TO KNOW ABOUT C++!!! I KNOW WHAT THERE'S TO KNOW FOR THE MOST PART, BUT I DON'T OVER-KNOW LIKE YOU NERDS! EVEN THOUGH I'M AND EVERYONE AT MY SCHOOL IS A NERD ANYWAY!!!