【发布时间】:2019-06-14 17:39:09
【问题描述】:
我的电脑显示sizeof unsigned long 和unsigned int 是一样的。
但是,当将参数传递给方法时……更具体地说是指针……我必须将unsigned int 重新转换为unsigned long。否则生成错误Compiler Error C2664":'function' : cannot convert argument n from 'type1' to 'type2'
为什么?
【问题讨论】:
-
因为它们是不同的类型。就像
struct Foo { int x; }和struct Bar { int x; }是不同的类型,即使它们具有相同的布局。 -
它们是不同的类型,大小也由实现定义see here
-
隐式转换不能通过指针进行。
-
产生该错误的代码示例将有助于使这个问题在未来对其他人更有用。