Thanks.
I never thoght about the copy constructor being involved.
It doesn't make sense to convert a primitive type to a class object
I saw a 'fuzzy' logic class which uses floating point numbers and uses both conversions in an article found in generation 5.com.
Code:
#include <iostream.h>
#include <math.h>
#include "fuzzy.h"
void main() {
fuzzy fz1 = 0.5, // 0.5
fz2 = (fz1 | 0.4f) & 0.45f, // 0.45//look below(1)
fz3 = !fz2 | fz2, // 0.55
fz4 = !(fz1 - fz2); // 0.95
bool bl5 = fz3.contained(fz2), // false
bl6 = fz2.contained(fz3); // true
cout << "Class 'fuzzy' logical operators:" << endl;
cout << "fz1 = " << fz1 << endl
<< "fz2 = " << fz2 << endl
<< "fz3 = " << fz3 << endl
<< "fz4 = " << fz4 << endl;
cout << endl;
cout << "bl5 = " << ((bl5) ? "true" : "false") << endl
<< "bl6 = " << ((bl6) ? "true" : "false") << endl;
}
Judging from the comments I've put in, I think you can guess the output of the program! Nevertheless,
you can see how easy it is to use the class. Just to reassure you, let us look at fz2 and fz3. fz2 is the
result of ((0.5 OR 0.4) AND 0.45). Remember OR takes the maximum, so that equates to 0.5,
and AND takes the minimum - therefore fz2 equals 0.45. On to fz3, that is (NOT(fz2) OR fz2) - the
NOT of fz2 is 1 - 0.45 = 0.55, which is bigger than 0.45.
The "contained" function returns
true iff A <= B. The class also has float type conversion routine, so you can use fuzzy and float synonymously
when pass parameters to functions(like cout::operator<<). You can download the code.....
(1)here they mixed float and fuzzy variables in an expression, thus implicitly converting the float var to fuzzy type