为什么我们需要构造函数? [英] Why we do need constructors?

查看:68
本文介绍了为什么我们需要构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我的朋友问我,为什么我们真的需要C ++的构造函数?我们可以在哪里用结构语言做同样的事情.构造函数的特长是什么,向我展示了构造函数的需求,因此我应该在C ++程序中使用它.请帮助我,并给我一些例子,以便我能够消除他的疑问.

Today my friend asked me, why really do we need constructors in C++? Where as we can do the same in structural language. What is the specialty of constructors, show me the need of constructors so that I should use it in my C++ program. Please help me and give me some examples so that I could able to clear his doubt.

推荐答案

与不需要 大部分功能的含义相同,您不需要 构造函数流行语言.

You don't need constructors in the same sense that you don't need most features of popular languages.

存在构造函数会使执行错误的事情更加困难.在这种情况下,请使用尚未初始化的数据.

Constructors exist to make it more difficult to do The Wrong Thing. In this case, using data that hasn't been initialized.

这篇关于为什么我们需要构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆