如何在C ++类的初始化器列表中初始化成员结构? [英] How to initialize member-struct in initializer list of C++ class?
本文介绍了如何在C ++类的初始化器列表中初始化成员结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在c ++中有以下类定义:
struct Foo {
int x;
char array [24];
short * y;
};
class Bar {
Bar();
int x;
Foo foo;
};
并且想在初始化器中初始化foostruct(及其所有成员)的Bar类。可以这样做:
Bar :: Bar()
:foo(),
x (8){
}
...?
或者在初始化器列表中 foo(x)做什么?