// Example program
#include <iostream>
#include <vector>
#include <array>
class A{
    public:
        A(int tempY){
            y = tempY;
        }
        int y = 0;
};
class B{
    public:
        B(A tempZ){
            z = tempZ.y;
        }
        A z;
};
int main()
{
    int x = 1;
    A objA(x);
    B objB(objA);
    std::cout << "y = " << objB.z << "!\n";
}
Build at: http://cpp.sh/3yj2
There is an error in class B because I haven't passed a constructor parameter to member z. I don't want to initialize it with a dummy value, is there a way to only use constructor parameters to build member z, and how do I tell z to use B's constructor parameters?
If I'm missing a fundamental aspect of C++ please let me know I'm just starting out.
 
     
    