サンプル
struct
CC
{
int
n;
char
c;
};
class
Point{
public
:
Point(
int
newx,
int
newy);
private:
int
x;
int
y;
CC myStructure;
};
Point::Point(
int
newx,
int
newy): x(newx) {
myStructure.n =
2
;
}
ソリューション
常にすべてのフィールドをコンストラクター内で初期化します。
struct
CC
{
int
n;
char
c;
};
class
Point{
public
:
Point(
int
newx,
int
newy);
private:
int
x;
int
y;
CC myStructure;
};
Point::Point(
int
newx,
int
newy) : x(newx), y(newy) {
myStructure.n =
1
;
myStructure.c =
'a'
;
}