隐式转换和显式转换之间的差异

隐式转换和显式转换之间的差异

本文介绍了隐式转换和显式转换之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

和显式转换?

推荐答案

显式转换是使用一些语法来 em>程序做一个转换。例如(在Java中):

An explicit conversion is where you use some syntax to tell the program to do a conversion. For example (in Java):

int i = 999999999;
byte b = (byte) i;  // The type cast causes an explicit conversion
b = i;              // Compilation error!!  No implicit conversion here.

隐式转换是指没有任何语法的转换。例如(在Java中):

An implicit conversion is where the conversion happens without any syntax. For example (in Java):

int i = 999999999;
float f = i;    // An implicit conversion is performed here

通常涉及表示的一些改变,并且可能导致精度的损失或信息的丢失。相比之下,涉及参考类型(仅)的转换不会更改基本表示。

It should be noted that (in Java) conversions involving primitive types generally involve some change of representation, and that may result in loss of precision or loss of information. By contrast, conversions that involve reference types (only) don't change the fundamental representation.

我不这么想。显然,可用的转换将是不同的,但是隐式和显式之间的区别将是相同的。 (注意:我不是C ++语言的专家...但是这些单词在英语中有一个自然的含义,我不能想象C ++规范在矛盾的意义上使用它们。)

I don't imagine so. Obviously the conversions available will be different, but the distinction between "implicit" and "explicit" will be the same. (Note: I'm not an expert on the C++ language ... but these words have a natural meaning in English and I can't imagine the C++ specifications use them in a contradictory sense.)

这篇关于隐式转换和显式转换之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:02