M
Michael Hopkins
Hi all
I have a subclass of valarray<T> thus
template <typename T>
class uo_val : public std::valarray<T>
{
public:
uo_val ( ) : std::valarray<T>() {}
uo_val (const int sz ) : std::valarray<T>( sz ) {}
uo_val (const int sz, const T fill ) : std::valarray<T>( fill, sz ) {}
//etc..
};
and I want to define an operator
uo_val& uo_val:perator=( const T & )
to assign all values to the supplied T using valarray's operator
valarray& valarray:perator=( const T & )
But neither (1) nor (2) below work and I'm not sure why.
uo_val& operator=( const T & val ) { // (1)
return std::valarray<T>:perator=( val );
}
Refuses to compile with:
error: invalid initialization of reference of type 'hr::uo_val<double>&'
from expression of type 'std::valarray<double>'
uo_val& operator=( const T & val ) { // (2)
*this = val;
return *this;
}
Compiles but gives runtime error signal 11 (SIGSEGV)
Could someone please enlighten me?
Many thanks - please CC to my email
Michael
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
I have a subclass of valarray<T> thus
template <typename T>
class uo_val : public std::valarray<T>
{
public:
uo_val ( ) : std::valarray<T>() {}
uo_val (const int sz ) : std::valarray<T>( sz ) {}
uo_val (const int sz, const T fill ) : std::valarray<T>( fill, sz ) {}
//etc..
};
and I want to define an operator
uo_val& uo_val:perator=( const T & )
to assign all values to the supplied T using valarray's operator
valarray& valarray:perator=( const T & )
But neither (1) nor (2) below work and I'm not sure why.
uo_val& operator=( const T & val ) { // (1)
return std::valarray<T>:perator=( val );
}
Refuses to compile with:
error: invalid initialization of reference of type 'hr::uo_val<double>&'
from expression of type 'std::valarray<double>'
uo_val& operator=( const T & val ) { // (2)
*this = val;
return *this;
}
Compiles but gives runtime error signal 11 (SIGSEGV)
Could someone please enlighten me?
Many thanks - please CC to my email
Michael
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _/ _/_/_/ Hopkins Research Ltd
_/ _/ _/ _/
_/_/_/_/ _/_/_/ http://www.hopkins-research.com/
_/ _/ _/ _/
_/ _/ _/ _/ 'touch the future'
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/