I get en error at a1.get()=7; which says no operator "=" matches these operands
There's no way to convert 7
to a A_Impl
for operator=
, because the constructor A_Impl(T)
, which in this instance is expanded to A_Impl(int)
, is declared explicit
.
You can either remove the explicit
keyword, or explicitly create an A_Impl
with:
a1.get() = A_Impl(7);
Alternatively you can also declare a specific operator=
:
const A_Impl& operator=(const T&)
for the A_Impl
class.
Also, if i take explicit word out it will compile, but i dont understand the difference between the a1.get() function and a1=13; which works fine even with explicit.
a1 = 13
works fine because the template class A
has a non-explicit constructor to T
(specifically A(T var)
), which, in this case, match perfect for T = int
.
Also notice that main
should always return int
, not void
.