注册 登录
编程论坛 C++教室

强类型语言中的强类型怎么理解?

newyj 发布于 2008-05-16 22:23, 730 次点击
强类型语言中的强类型怎么理解?
5 回复
#2
dubaoshi2008-05-17 09:52
是指一个变量被声明为某种类型的话,那么不经强制转换的话,是不可赋给其他类型的数据。
比如:int *p;在未强制转换类型前,不可能指向一个string的地址。
#3
newyj2008-05-17 11:08
那C++好象 能隐式转换啊 不用强制转换
那C++是不是 强类型语言
#4
dubaoshi2008-05-17 11:27
虽然有隐式转换,比如:int i=5.6;这样是可以,因为经过了隐式转换,但实际上变量i存的值是多少呢?只能是5,不会是5.6的,所以说隐式转换也不能叫i存一个float数值。
#5
flyue2008-05-17 13:31
用强制转换哪怕你是男的都可以给你转换成女的,强制就是不管是什么类型都把它扭过来,只是会不会发生错误的问题了
#6
rhyme2008-05-17 20:40
"strong   typing "   implies   that   the   programming   language   places   severe   restrictions   on   the   intermixing   that   is   permitted   to   occur,   preventing   the   compiling   or   running   of   source   code   which   uses   data   in   what   is   considered   to   be   an   invalid   way.

weakly-typed   programming   languages   are   those   that   support   either   implicit   type   conversion   (nearly   all   languages   support   at   least   one   implicit   type   conversion),   ad-hoc   polymorphism   (also   known   as   overloading)   or   both.
1