I've recently been perplexed by an error and it is halting my progress. Here is a minimal example showing the problem:
template <typename first, class second>
struct Example{
enum Bits{
Bit1 = 1,
Bit2 = 2
};
};
template <typename first, class second>
inline typename Example<first, second>::Bits foo(typename Example<first, second>::Bits lhs,
typename Example<first, second>::Bits rhs)
{ return typename Example<first, second>::Bits(static_cast<unsigned int>(lhs) | static_cast<unsigned int>(rhs)); }
int main(){
Example<int, int>::Bits b1 = Example<int, int>::Bit1;
Example<int, int>::Bits b2 = Example<int, int>::Bit2;
foo(b1, b2);
return 0;
}
When I attempt to compile this, I get the error:
tests/file_test.cpp:20:19: error: no matching function for call to ‘foo(Example<int, int>::Bits&, Example<int, int>::Bits&)’
tests/file_test.cpp:20:19: note: candidate is:
tests/file_test.cpp:10:46: note: template<class first, class second> typename Example::Bits foo(typename Example<first, second>::Bits, typename Example<first, second>::Bits)
tests/file_test.cpp:10:46: note: template argument deduction/substitution failed:
tests/file_test.cpp:20:19: note: couldn't deduce template parameter ‘first’
Can anyone point out the issue in the above code? To me, the template parameter is obvious.