对C++不是类型安全语言的理解

参见脚本之家:http://www.jb51.net/article/37847.htm

在C++中,可以把0当成bool类型的false,也可以当做int中的数字0.则表示C++不是类型安全语言。

类似的,MFC中的CString也不是类型安全的类。因为其他类型的数据可以通过CSting中的成员函数Format转换成CString。

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5  bool fun()//函数返回类型是bool,但是我们在函数中可以返回int类型。
 6  {
 7      return 1;
 8  }
 9 
10  void main()
11  {
12      int a=1;
13      if(a)//a是int类型的,但是可以作bool类型来使用。
14      {
15          cout<<"C++是非类型安全的。"<<endl;
16      }
17      
18  }
原文地址:https://www.cnblogs.com/cnblogsnearby/p/4628373.html