为什么在c ++中的结构不需要构造函数? [英] Why structures in c++ don't need constructor?
本文介绍了为什么在c ++中的结构不需要构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从2年左右开始做C ++,我说为什么我们需要在类中而不是在结构中的构造函数,为什么我们不能在结构中构造函数重载...
I am doing C++ from 2 years or so , I say why we need constructors in class and not in structures , and why we cant do constructor overloading in structure...
推荐答案
为什么我们需要类
why we need constructors in class
不要。
// Perfectly valid
class Foo
{
public:
int x
};
为什么我们不能在结构中重构构造函数...
why we cant do constructor overloading in structure...
我们可以。
// Look, ma!
struct Bar
{
Bar operator+(const Bar& other);
};
我不知道你在哪里听到这些声明,但它肯定不是从尝试。
I don't know where you heard these claims but it certainly wasn't from trying it out.
用关键字<$ c'声明的用户定义类型$ c> struct 是类。
这篇关于为什么在c ++中的结构不需要构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文