我试图在Visual C++ 2010中实现智能相等测试宏类型模板函数时遇到了一些麻烦,该函数与VS中关于模板函数的默认参数的错误有关.我通过在额外的函数中包装参数的值来修复它,但现在我发现我不能在一行中使用该函数两次!
头文件:
// example.h
#pragma once
#include <limits>
namespace myspace
{
// Need to define this separately to avoid a Visual Studio bug
template<typename T> T epsilon() { return std::numeric_limits<T>::epsilon(); }
// A generic equality test
template<typename T> inline bool smartEqual(
const T &v1,
const T &v2,
const T &eps = epsilon<T>())
{
return (v1 == v2);
}
// Template specialization for floating-point numbers
template<> bool smartEqual<float>(
const float &v1,
const float &v2,
const float &eps); …Run Code Online (Sandbox Code Playgroud)