I've got the following sample code and would like to get some help to understand why I am unable to compile it using clang and g++ on Linux?
#include <iostream>
using namespace std;
typedef enum COLORS {
RED = 0,
GREEN,
BLUE,
ORANGE,
MAROON,
WHITE,
BLACK
} COLORS;
template <COLORS C> void whatColor( COLORS x ) {
cout << "this can be any color!!!" << endl;
}
template<> void whatColor<RED>( COLORS x ) {
cout << "this is RED!!!" << endl;
}
template<> void whatColor<GREEN>( COLORS x ) {
cout << "this is GREEN!!!" << endl;
}
template<> void whatColor<BLUE>( COLORS x ) {
cout << "this is BLUE!!!" << endl;
}
template<> void whatColor<ORANGE>( COLORS x ) {
cout << "this is ORANGE!!!" << endl;
}
int main( ) {
const COLORS red=RED;
whatColor( red );
whatColor<RED>( RED );
whatColor<red>( red );
whatColor<RED>( red );
}
The failure I am seeing is this:
CXX [misc] tmpl.cpp
src/tmpl.cpp:40:2: error: no matching function for call to 'whatColor'
whatColor( red );
^~~~~~~~~
src/tmpl.cpp:15:26: note: candidate template ignored: couldn't infer template argument 'C'
template <COLORS C> void whatColor( COLORS x ) {
^
1 error generated.
make: *** [obj/tmpl.o] Error 1
It is unclear to me why it cannot infer the argument type in this case