由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问几个问题
相关主题
c++ 中如何把str转换为float?Is it safe?
谁给解释一下这个c question有关objec access path的问题
C++ questionWhy does default exception use char *?
question about const referencewhy int** cannot convert to const int** ?
Anybody help me on these questions?问一个打开文件的问题
strlen怎么实现的C++ Strategies and Tactics 书上一个问题求助
请教一个关于字符指针的简单问题C库函数:strpbrk() 的实现一问
c++ string 一问c++ 得最基本问题
相关话题的讨论汇总
话题: int话题: words话题: const话题: double话题: min
进入Programming版参与讨论
1 (共1页)
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.
1 (共1页)
进入Programming版参与讨论
相关主题
c++ 得最基本问题Anybody help me on these questions?
蔡鸟C++ 类型问题strlen怎么实现的
a simple C++ question请教一个关于字符指针的简单问题
a string define question (c++)c++ string 一问
c++ 中如何把str转换为float?Is it safe?
谁给解释一下这个c question有关objec access path的问题
C++ questionWhy does default exception use char *?
question about const referencewhy int** cannot convert to const int** ?
相关话题的讨论汇总
话题: int话题: words话题: const话题: double话题: min