Originally Posted by
brewbuck
The problem is that when a reference is created it MUST be seated to another variable. In the following code, where exactly does that reference get seated?
Code:
std::complex<double &> val;
std::complex will attempt to default-construct the real and imaginary parts -- but since these parts are of type "double &" there is no such default constructor.
Well I tried to contruct it like
Code:
double x,y ;
std::complex<double &> val(x,y) ;
But I'm having some issues with the roll your own complex reference class as well. If I want to implement a forward iterator it seems I can either support reading the values or assigning the values but not both.
The problem is how can I write an assignment operator that assigns a class of type complex_ref to the class std::complex<double> ?
Code:
typedef std::complex<double> complexd
complexd & complexd::operator=(complex_ref &u)
{
this->real() = u.real() ;
this->imag = u.imag() ;
return *this ;
}
unfortunately complexd->real() is a const reference, assignment shouldn't be able to work.
Maybe this? (based on your implementation)
Code:
typedef std::complex<double> complexd
complexd & complexd::operator=(complex_ref &u)
{
*this = u.complexd() ;
return *this ;
}
O wait maybe I'm misunderstanding something.
Code:
operator complexd() const
{
return (complexd(real,imag)) ;
}
Does this overload a type cast or something? This syntax is new to me. If so is the type cast applied automatically?