L
Lippman.Gan
Sorry for that I can not clarify the type of issue in topic.
Look the code below:
template <class T>
class A
{
public:
class a
{
public:
a(int elem):x(elem){cout<<"a::a()\n";}
~a(){cout<<"a::~a()\n";}
int GetX(){return x;};
private:
int x;
};
A(a _a1):a1(_a1){cout<<"haha"<<endl;}
private:
a a1;
friend bool operator ==(const A<int>& t1,const A<int>& t2)
{
cout<<"operator=="<<endl;
return true;
}
};
int main()
{
A<int> b(10); //This would be OK, why?
if(b==10){cout<<"success\n";} //Why this can not run?
return 0;
}
I see in main()
L1, 10 is an integer it implicitly transfer to class a
L2, 10 is also an integer, but it can not implicitly transfer.
why L1 can do this but L2 can not?
Look the code below:
template <class T>
class A
{
public:
class a
{
public:
a(int elem):x(elem){cout<<"a::a()\n";}
~a(){cout<<"a::~a()\n";}
int GetX(){return x;};
private:
int x;
};
A(a _a1):a1(_a1){cout<<"haha"<<endl;}
private:
a a1;
friend bool operator ==(const A<int>& t1,const A<int>& t2)
{
cout<<"operator=="<<endl;
return true;
}
};
int main()
{
A<int> b(10); //This would be OK, why?
if(b==10){cout<<"success\n";} //Why this can not run?
return 0;
}
I see in main()
L1, 10 is an integer it implicitly transfer to class a
L2, 10 is also an integer, but it can not implicitly transfer.
why L1 can do this but L2 can not?