May 12th, 1999, 04:54 PM
I have written the following class as a basis for a 'double' type that can check for a NULL value.
class CMyDouble
{
public:
CMyDouble() {m_no = 0.0;}
CMyDouble(const double &no) {*this = no;}
double & operator=(const double &no) {return m_no = no;}
operator double&() {return m_no;}
operator const double&() const {return m_no;}
private:
double m_no;
};
I have tested the class with the following code.
void func(double)
{
}
CMyDouble no = 1;
CMyDouble no2;
double dbl;
double dbl2 = no;
no = 1;
no2 = 1;
dbl = no;
no = dbl;
no2 = no;
(no > dbl);
(dbl > no);
(no2 > no);
dbl+=no;
dbl*=no;
no+=dbl;
no/=dbl;
no+=1;
func(no);
which all works fine except for the line "dbl = no", which generates the error message "'operator =' is ambiguous". If I cast the CMyDouble to a double there is no problem, i.e. "dbl = (double)no" is ok. Why am I getting this error and is there any way around it?
Thanks for your help.
class CMyDouble
{
public:
CMyDouble() {m_no = 0.0;}
CMyDouble(const double &no) {*this = no;}
double & operator=(const double &no) {return m_no = no;}
operator double&() {return m_no;}
operator const double&() const {return m_no;}
private:
double m_no;
};
I have tested the class with the following code.
void func(double)
{
}
CMyDouble no = 1;
CMyDouble no2;
double dbl;
double dbl2 = no;
no = 1;
no2 = 1;
dbl = no;
no = dbl;
no2 = no;
(no > dbl);
(dbl > no);
(no2 > no);
dbl+=no;
dbl*=no;
no+=dbl;
no/=dbl;
no+=1;
func(no);
which all works fine except for the line "dbl = no", which generates the error message "'operator =' is ambiguous". If I cast the CMyDouble to a double there is no problem, i.e. "dbl = (double)no" is ok. Why am I getting this error and is there any way around it?
Thanks for your help.