我需要在 C++ 中有以下结构的类。
class A
{
int y;
A(int x)
{
//Computes y as per x.
}
};
class B
{
A obj;
int w;
B(int z)
{
//Need to call constructor of obj with input x = z
//Need to set the value of w based on value of A.y
//How to do it?
}
};
我在互联网上找不到如何执行此操作。 obj
的构造何时会被调用,以及如何使用输入 z 调用它?