新操作员的功能 [英] Functioning of new operator
本文介绍了新操作员的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Class student
{
string name;
string address;
public student(string n,string m)
{
name=n;
address=m;
}
}
student st=new student(hena,New delhi);
解释当上一行被调用时发生的过程
explain me process take place when when above line is called
推荐答案
实际上,新的运算符用于在堆上创建对象并调用构造函数.
在上面的几行中,当学生st =新学生(hena,新德里)时;行执行后,学生构造函数将自动调用并创建st对象.
Actually new operator is used to create objects on the heap and invoke constructors.
In above lines,when student st=new student(hena,New delhi); line executed, the student constructor invokes automatically and st object is created.
在MSDN上 [^ ]
您甚至还没有意识到您在代码示例的最后一行中编写了什么内容,因此无法编译.仿佛
Did you even realize what have you written in the last line of you code sample, which will not compile. As if
Delhi NewDelhy = new Delhy()
:-)
:-)
这篇关于新操作员的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文