This assignment is not yet finished, but I can not figure out why it will not run as is. It is supposed to calculate "the money earned for 4 separate quarters, of 6 separate divisions" of a sales company using class inheritance, object composition and the "has a relationship". When I try to run this I get error messages that I don't understand. I posted them on the lines indicated by the compiler. I am using VS 2013.
}
/*Error 9 error C2614: 'DivSales' : illegal member initialization: 'Q1comp' is not a base or member
Error 10 error C2614: 'DivSales' : illegal member initialization: 'Q2comp' is not a base or member
Error 11 error C2614: 'DivSales' : illegal member initialization: 'Q3comp' is not a base or member
Error 12 error C2614: 'DivSales' : illegal member initialization: 'Q4comp' is not a base or member c*/
};
/*************************************
* main() *
* the main takes the sales earned *
* for each quarter for each devison *
* of the company *
*************************************/
int main()
{
int Q0 = 1, Q1 = 1, Q2 = 1, Q3 = 1;
DivSales Div1(Q0, Q1, Q2, Q3);
for (int i = 0; i < 6; i++)
{
cout << "what were the sales figures for quarter 0? /n ";
cin >> Q0;
cout << "what were the sales figures for quarter 1? /n ";
cin >> Q1;
cout << "what were the sales figures for quarter 2? /n ";
cin >> Q2;
cout << "what were the sales figures for quarter 3? /n ";
cin >> Q3;
if (i == 1)
{
DivSales Div1(Q0, Q1, Q2, Q3);
}
else if (i == 2)
{
DivSales Div2(Q0, Q1, Q2, Q3);
}
else if (i == 3)
{
DivSales Div3(Q0, Q1, Q2, Q3);
}
else if (i == 4)
{
DivSales Div4(Q0, Q1, Q2, Q3);
}
else if (i == 5)
{
DivSales Div5(Q0, Q1, Q2, Q3);
}
else if (i == 6)
{
DivSales Div6(Q0, Q1, Q2, Q3);
}
}
This is essentially the inheritance structure you have in your code and it is nonsensical.
In order for an instance of A to contain a B object, an A must know the full definition of the B type, but at the point where A needs to know this, A is still being defined. And since B inherits from A, B's definition is clearly not complete yet either.
If, somehow, you were able to get the compiler to compile this mess, construction of type B would result in a conundrum. A B object contains a B object. And the B object it contains, also contains a B object which also contains a B object which also contains a B object...
Also, there is no reason to have a type for each quarter. Have one type and four instances of the type.