l******n 发帖数: 9344 | 1 1。class Say
{
int words(int i);
public:
double words(double d);
float words(float f);
char words(char c);
};
void SayWords()
{
Say s;
s.words(32.0);
}
call SayWords为什么是double words invoked?
2.template
T min(const T &a, const T &b) {
return (a < b) ? a : b;
}
template<>
int min(const int &a, const int &b) {
return (a < b) ? a : b;
}
int min(int a, int b) {
return (a < b) ? a : b;
}
void f() {
int m = min(10, 20);
}
Question Referring to the sampl |
j*****s 发帖数: 16 | 2 1. Why not the double function? 32.0 has type double.
【在 l******n 的大作中提到】 : 1。class Say : { : int words(int i); : public: : double words(double d); : float words(float f); : char words(char c); : }; : void SayWords() : {
|
l******n 发帖数: 9344 | 3 why not float?
【在 j*****s 的大作中提到】 : 1. Why not the double function? 32.0 has type double.
|
j*****s 发帖数: 16 | 4 32.0f是float类型。
另外第二题应该是调用int min(int a, int b)函数。已经有精确匹配了,
不会再对模版展开了吧。
【在 l******n 的大作中提到】 : why not float?
|
l******n 发帖数: 9344 | 5 哦
thanks
如果是sayword(32)呢?为什么还是用double?
【在 j*****s 的大作中提到】 : 32.0f是float类型。 : 另外第二题应该是调用int min(int a, int b)函数。已经有精确匹配了, : 不会再对模版展开了吧。
|
j*****s 发帖数: 16 | 6 sayword(32)能通过编译吗?
【在 l******n 的大作中提到】 : 哦 : thanks : 如果是sayword(32)呢?为什么还是用double?
|
l******n 发帖数: 9344 | 7 yes, I tried it workds.
【在 j*****s 的大作中提到】 : sayword(32)能通过编译吗?
|
t****t 发帖数: 6806 | 8 time to upgrade your compiler. it should NOT pass compile.
【在 l******n 的大作中提到】 : yes, I tried it workds.
|