Reputation: 7636
//#include <string>
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
template<class T, class X> class Obj{
T my_t;
X my_x;
public:
Obj(T t, X x):my_t(t),my_x(x){}
operator T() const {return my_t;}
};
int main()
{
int iT;
Obj<int, float> O(15,10.375);
iT = O;
cout << iT << endl;
return O;
}
about this line : operator T() const {return my_t;}
is this operator overload? but I am not so understand which operator is been overloaded?
anybody can explain it for me? thanks!
Upvotes: 2
Views: 213
Reputation: 76640
Yes, that is operator overloading. The operator that has been overloaded is the casting operator to type T
. That's the operator that is invoked when you ask the compiler to convert an Obj<T,X>
into a T
.
Upvotes: 5