i have a question about explicit and templates:
template<class T>
class A {
class A_Impl {
T var;
public:
explicit A_Impl(T var1) : var(var1), version(1)
{
}
A_Impl(const A_Impl& a ) : var(a.var), version(1)
{
}
const A_Impl& operator=(const A_Impl& a)
{
var=a.var;++version;return *this;
}
operator T() const { return var; }
friend class A<T>;
};
A_Impl a;
public:
A(T var): a(var)
{
}
A_Impl& get() { return a; }
};
void main() {
A<int> a1(5);
cout<<"a1 = "<<a1.get()<<endl;
a1.get()=7;
cout<<"a1 = "<<a1.get()<<endl;
a1=13;
cout<<"a1 = "<<a1.get()<<endl;
}
I get en error at a1.get()=7;
which says no operator "=" matches these operands
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.