隐式转化虽然讲起来简单,但在实践过程中却很容易因为疏忽而犯错.比如下面这个程序
#include "stdafx.h"
#include "stdlib.h"
#include<iostream>
using namespace std;
int _tmain()
{
double a=3/2; //a虽然定义成浮点型,但是结果却是1
cout<<a<<endl;
system("pause");
return 0;
}
所以推荐的做法应该是将3写成3.0,2写成2.0,这样就是浮点数运算了.