Now I know why I was trying to explicitly call the conversion operator. In my application the type is complex. This gets ambiguous with the complex copy constructor.
Any thoughts on this one?
#include <string>
#include <complex>
using namespace std;
class MyType
{
public:
MyType() {}
~MyType() {}
operator char() const { return 'a'; }
operator int() const { return 1; }
operator double() const { return 2.0; }
operator float() const { return 3.0f; }
operator complex<double>() const { return complex<double>(1.0,1.0); }
};
template<typename ValType>
void setType(const MyType& val)
{
ValType type;
type = static_cast<ValType>(val);
}
int main()
{
MyType a;
setType<complex<double> >(a);
return 0;
}
#include <string>
#include <complex>
using namespace std;
class MyType
{
public:
MyType() {}
~MyType() {}
operator char() const { return 'a'; }
operator int() const { return 1; }
operator double() const { return 2.0; }
operator float() const { return 3.0f; }
operator complex<double>() const { return complex<double>(1.0,1.0); }
};
template<typename ValType>
void setType(const MyType& val)
{
ValType type;
type = static_cast<ValType>(val);
}
int main()
{
MyType a;
setType<complex<double> >(a);
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks