Hi,
I want to do this exercise
Define two classes, each with a static member,
so that the construction of each static member involves a reference to the other.
Where might such constructs appear in real code?
How can these classes be modified to eliminate the order dependence in the constructors?
Is my code correct?
Code:#include <iostream> using namespace std; class StepOne { int num; public: StepOne() { cout << "StepOne's constructor called " << endl; } }; class StepTwo { static StepOne first; public: StepTwo() { cout << "StepTwo's constructor called " << endl; } static StepOne getStepOne() { return (first); } }; StepOne StepTwo::first; int main() { StepTwo st1, st2, st3; StepOne first = st1.getStepOne(); return (0); }