我創造了這個struct
了一些簡單的模板數學定義:C++:默認模板參數只有當使用推斷 「<>」
template<class T = float> struct Math{
static constexpr T PI = T(3.14159265359);
static constexpr T E = T(2.718281828459);
static constexpr T INF = std::numeric_limits<T>::infinity();
};
我想用這樣的:
float pi = Math::PI;
即使默認參數T
是float
我也會得到錯誤:
'template<class T> struct Math' used without template parameters
如果我使用Math<>::PI
它可以工作。這是一個編譯器錯誤還是<>
括號是強制性的?
爲什麼你不使用'雙'所有他們? –