c++ - Set default comparison type in Template -
i want set default class type default comparison type in template , want compares 2 character strings using templates, did write code it’s giving error. code , error given below,
class casesencmp{ public:      static int isequal(char x, char y){        return x==y;    } };  template<typename c=casesencmp> int compare(char* str1, char* str2){   for(int i=0; i<strlen(str1) && i<strlen(str2); i++)     if(!c::isequal(str1[i], str2[i]))         return str1[i]-str2[i];   return strlen(str1)-strlen(str2);  }  main(){ char *x = "hello", *y = "hello"; compare(x,y);    }   but when have added prototype of template, works
template<typename c>   compiler gives error
error: default template arguments may not used in function templates without -std=c++11 or -std=gnu++11|   also when try type casting in main function using code, works
compare<casesencmp>(x,y);   but want set default policy
i faced issue in code::blocks. tackle issue have enable
-std=c++11   into compiler. in case of code::blocks have follow given below instructions.
settings->compiler->compiler flags...look , check option "have g++ follow c++11 iso c++ language standard". if doesn't check box above c++0x standard.
Comments
Post a Comment