|
Boost : |
From: helmut.zeisel_at_[hidden]
Date: 2001-10-31 06:36:13
I want to specialize numeric_cast for a user definied class.
GCC 3.0.1 compiles the following code,
Visual C++ 6.0 says
example_numeric_cast.cpp(20) : error C2572: 'numeric_cast' :
redefinition of default parameter : parameter 2
example_numeric_cast.cpp(19) : see declaration of 'numeric_cast'
Is the code correct?
If yes, what is a suitable work around for VC++?
--------- Code example
#include <boost/cast.hpp>
# if defined(BOOST_MSVC) && BOOST_MSVC <= 1200 // 1200 = VC6
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<myint>* a=0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# endif
namespace boost
{
class myint
{
public:
myint() {}
};
template<> myint numeric_cast(double arg
BOOST_EXPLICIT_DEFAULT_TARGET)
{
myint result;
return result;
}
}; // namespace boost
int main()
{
boost::myint a = boost::numeric_cast<boost::myint>(0.5);
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk