#include <iostream>
#include <string>
#include <type_traits>
using namespace std;
struct boy_tag
{
};
struct girl_tag{
};
struct boy
{
void eat() const
{
cout << "eat two bowls";
}
};
struct girl
{
void eat() const
{
cout << "eat one bowl"<<endl;
}
};
template <typename T>
void eat(T student, girl_tag)
{
cout << "---"
<< "girl"
<< "---" << endl;
student.eat();
}
template <typename T>
void eat(T student, boy_tag)
{
cout << "---"
<< "boy"
<< "---" << endl;
student.eat();
}
template <typename T>
void eat(T student)
{
bool flag = is_same<decltype(student), boy>::value;
if(flag){
eat(student,boy_tag{});
}else{
eat(student,girl_tag{});
}
}
int main(void)
{
girl g;
boy b;
// eat(g);
eat(b);
return 0;
}
07-11
3118
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-29
1290
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-17
6万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-28
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交