C++ unexplained variations in template function matching with enums -


i have following code containing template function. when calling function second parameter being enum: in cases finds template specialization , in cases not.

i had verified enums same enums in both cases (e.g there no redefinitions) , other parameters have correct values, found 1 compilation done -winline set (i did not try changing yet) else at?

class { public:     template <typename t>     int f(uint32_t id, t const& t, bool cond);      ... };  template <typename t> int a::f(uint32_t id, t const& t, bool cond) {    ... }  template <> inline int a::f<int>(uint32_t, int const& t, bool cond) {    .... } 

for starters, typically, it's inadvisable use template specialization way of overloading template function. template specializations interact poorly function overloading , have pretty arcane rules dictating when they're chosen, , in general it's considered better provide regular function overload specialize function template.

in case, i'd advise changing class this:

class { public:     template <typename t>         int f(uint32_t id, t const& t, bool cond);     int f(uint32_t id, int t, bool cond);     ... }; 

then changing template specialization implementation of overload. due way c++ function overloading works, select correct version of function more accurately.

as particular question, reason code isn't calling overload c++ makes distinction between enumerated type , type int. though there ways of converting between ints , enumerated types, aren't same thing, , overload designed catch ints not guaranteed catch enumerated types well. better off overloading function handle enumerated case.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -