[c/c++] "? :" 在何种状况下不能修改为"if (..) {..} else {..}"?
2007-10-22 13:32
435 查看
#include <iostream>
using namespace std;
void f(double)
...{
cout << "double" << endl;
}
void f(int)
...{
cout << "int" << endl;
}
int main()
...{
f(true ? 1 : 1.0);
if(true)
...{
f(1);
}
else
...{
f(1.0);
}
}
//输出
//double
//int
"当以“f(true ? 1 : 1.0);”的形式调用式,f的实参是表达式“true ? 1 : 1.0”,C/C++语言中,一个表达式不可能同 时有两种类型,所有,f的调用必将绑定到一个确定的重载上去。而第二种情况中,if和else分支中的两次调用,按照C++语言的重载解析规则,显然是不 一样的,是实实在在的两种情况。"
相关文章推荐
- <s:if test="canSubscribe == 'Y'">能 </s:if> <s:else>不能 </s:else> 单字符需加.toString()
- <s:if test="canSubscribe == 'Y'">能 </s:if> <s:else>不能 </s:else> 单字符需加.toString()
- 使用VS2010在项目中编写C++头文现出"PCH 警告:标头停止点不能位于宏或#if块中"
- iOS开发:发布证书无法安装,不能修改"System Roots"钥匙串
- C/C++学习(一)题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。
- 关于"显示所有文件和文件夹"不能修改的问题
- jstl 的if else <c:choose><c:when test="">如果</c:when><c:otherwise>否则</c:otherwise></c:choose>
- "getline" bug fix for Microsoft Visual C++ 6.0 关于VC6的getline输入需要两个回车才结束的BUG修改方法
- 比较两个整数的大小,不能使用 &quot;if&quot;, &quot;?:&quot;, &quot;switch&quot; 等
- C++ "multiple definition of .. first defined here 错误的修改
- 【C++】不能将“this”指针从“const vector”转换为“vector & rhs"
- 注意在<s:if test="#session.user.power==0">中不能用 <s:if test=$sessionScope.user.power==0">
- 题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)
- SQL"已更新或者删除的行值要么不能使该行成为唯一行,要么改变了多个行(X行)“解决办法
- C++项目中的extern "C" {}
- 解决android studio ADB无响应的问题:If you'd like to retry,then please manually kill "adb.exe"
- 一道简单的面试题(求较小的值,不能用 比较运算符 if-else ?: while for 内嵌汇编 递归 第三方函数)(zt)
- 求1+2+…+n,要求不能使用乘除法、for、while、if、else...
- 关于Spring的destroy-method和scope="prototype"不能共存问题
- 创建触发器后不能进行修改操作,Can't update table 'psxt_user' in stored function/trigger because