Operator typename () const is used for type conversion
C ++ can convert the data type by default or forcibly convert the data type. The overload conversion operator is used to facilitate the conversion operation on the objects generated by the class, it must be a member function that implements class type conversion and can only be applied to one conversion. Continuous Conversion operations are not allowed.
Template <typename T>
Class base
{
Public:
Base (T &);
// Type conversion Constructor
Operator T () const
{
Return typet;
// This is required. Otherwise, an error will be reported.
}
// Operator type conversion
PRIVATE:
};
For example:
Template <class T>
Class {
Public:
Operator T () {// type conversion operation
Return _;
}
Operator T () const {// type conversion operation
Return _;
}
T & operator = (const T & ){
_ At =;
Return _;
}
PRIVATE:
T _;
};
Int main ()
{
A <int>;
A = 1;
Int c =;
// A =-;
// A = a + 1;
}