C ++中的结构构造函数? [英] Struct Constructor in C++?

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

问题描述

一个 struct 在C ++中有一个构造函数?

Can a struct have a constructor in C++?

我一直在试图解决这个问题,

I have been trying to solve this problem but I am not getting the syntax.

推荐答案

在C ++中,类之间的唯一区别 struct 是成员和基类默认在类中是私有的,而在struct中默认是public。

In C++ the only difference between a class and a struct is that members and base classes are private by default in classes, whereas they are public by default in structs.

所以结构体可以有构造函数,语法与类相同。

So structs can have constructors, and the syntax is the same as for classes.

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

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