Is there a way to get a constructor to act explicit in only certain functions?
Is there a way to get a constructor to act explicit in only certain functions?
No, not that I know of. I can't think of any reason why you would need to either; care to enlighten me?Originally posted by Trauts
Is there a way to get a constructor to act explicit in only certain functions?
my "any" type has a constructor that takes any type.
This is a pain because of overloads:
Gives you an error saying that it cannot choose between different overloads. (i.e. it tries to treat an int as an any...)Code:template <typename UnknownType> bool operator !=(const any & lhs, const UnknownType & rhs) {
Making the constructor explicit works, but then there's this problem:
needs to beCode:any x; x = 5;
Code:any x; x = (any)x;
Last edited by Trauts; 05-16-2003 at 07:34 PM.
I think I found a way to do it...
instead of
I triedCode:template <typename UnknownType> bool operator !=(const any & lhs, const UnknownType & rhs) { if (lhs.type() == typeid(UnknownType)) // check that types are same. // no support for compatible but not same, // sorry. Too much work to check for // int and float, etc. return any_cast<UnknownType>(lhs) != rhs; return false; // returns a copy of result }
Code:template <any, typename UnknownType> bool operator !=(const any & lhs, const UnknownType & rhs) { if (lhs.type() == typeid(UnknownType)) // check that types are same. // no support for compatible but not same, // sorry. Too much work to check for // int and float, etc. return any_cast<UnknownType>(lhs) != rhs; return false; // returns a copy of result }
That worked on all of the overloads except the stream ones...
How might I fix this?