本文介绍了隐式赋值比显式赋值的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
隐式赋值比显式赋值有什么优势?
考虑下面的示例:
What is the advantage of implicit assignment over explicit assignment?
Consider the below example:
class base
{
int b;
public:
base()
{
b = 0;
}
base(int x):b(x)
{
}
};
int _tmain(int argc, _TCHAR* argv[])
{
class base bobj(44);
return 0;
}
通常,我已经看到类中的变量是使用隐式赋值进行初始化的,即使对于上面显示的标准数据类型也是如此.
为什么会这样呢?
下面显示的显式分配也具有相同的作用:
Normally I have seen variables in class are initialized with implicit assignment even for the standard data types as shown above.
Why it is preferred so?
The explicit assignment shown below also does the same thing:
base(int x)
{
b = x;
}
那么为什么隐式优先于显式呢?
base(int x):b(x)优于
的优点是什么base(int x)
{
b = x;
}
?
Then why is implicit preferred over explicit?
What is the advantage of base(int x):b(x) over
base(int x)
{
b = x;
}
?
推荐答案
这篇关于隐式赋值比显式赋值的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!