C++: Default template argument only deduced when using "<>" -


i created struct easy templated math definitions:

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(); }; 

i use this:

float pi = math::pi; 

even if default argument t float ill error:

'template<class t> struct math' used without template parameters 

if use math<>::pi works. compiler bug or <> brackets mandatory?

yes <> brackets mandatory (see here).

but here other options:

use typedef

typedef math<> mydefaultmath // or typedef math<float> myfloatmath 

or drop template

struct math {     static constexpr float pi = 3.14159265359f;     // ... 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -