On 12-May-17 4:07 PM, fl wrote:
> [snip] When I run below code, I find one calls assignment
> while the other calls copy constructor.
You mean, one declaration uses the converting constructor while the
other uses the copy constructor.
> It is obvious it is caused by the
> template parameter <W>. It is still a surprise to me. I thought both should
> call copy constructor. Can you explain it to me?
`sc_biguint<3>` is a different type than `sc_biguint<4>`. So an instance
of the first can't be used directly where a reference to the second is
required, or vice versa. This rules out use of the copy constructor in
one case: it can't be called with an argument that can't be converted to
the type of the formal argument.
However, these types share a common base class.
> Thanks,
>
> //////////////////
> const sc_biguint<4> atomwrj1(2);
> sc_biguint<3> atomwrj0=atomwrj1; // Thus calls assignment constructor
> sc_biguint<4> atomwrj2=atomwrj1; // This calls copy constructor
>
> // copy constructor
> sc_biguint( const sc_biguint<W>& v )
> : sc_unsigned( W )
> { *this = v; }
>
> // assignment constructor
> sc_biguint( const sc_unsigned& v )
> : sc_unsigned( W )
> { *this = v; }
>