我有一个简单的程序:
int foo(int a){return a;}
double foo(double b){return b;}
int main(){
foo(1);
foo(1.0);
/*some template guard to not call at all not implemented function*/ foo("bar");
return 0;}
我可以写一些模板保护/宏,以不调用或不编译未实现/重载的函数吗?
因此,对于这个特定的需求,我使用了:
template <typename T,std::enable_if_t<!std::is_fundamental<T>::value, int> = 0>
inline int foo(T ntc) {return -1;}
这重载了我的函数thx@AsteroidsWithWings 的每一次错误使用