I have a piece of code that looks like this
Basically, I have a Customer class and the Customer selects from a list of offers from a vector which is defined inside the Customer class.
Code:
for (vector<Customer>::iterator CIt = i_CustomersList.begin(); CIt != i_CustomersList.end(); CIt++)
{ for (int i = 0; i < 3; i++)
{
Offer Contract = CIt->selectOffer(i);
//Contract.display(); cout<<endl;
CIt->setCurrentContract(Contract,i);
}
}
Now the setCurrentContract method is defined in the Customer Class as:
Code:
void setCurrentContract(Offer ContractOffer, int ProdIndex)
{
cout<<endl<<"***************************************"<<endl;
cout<<endl<<"Displaying from set Curr. Contr. method"<<endl;
c_Contract[ProdIndex] = &ContractOffer;
c_Contract[ProdIndex]->display();
cout<<endl<<endl;
//cout<<endl<<"Selected"<<endl;
}
c_Contract is declared thus
Code:
Offer * c_Contract[3]
Now when I am printing the offers from the setCurrentContract method as shown above the correct contracts are being output.
However, when I am trying to do this:
Code:
for (vector<Customer>::iterator CIt = i_CustomersList.begin(); CIt != i_CustomersList.end(); CIt++)
{
for (int i = 0; i<3;i++)
{CIt->displayContracts();}
}
only the last offer is output for all the contracts.
the displayContracts method is :
Code:
void displayContracts()
{
for( int i = 0; i < 3; i++ )
{ cout<<endl<<"ProdIndex"<<i<<endl;
if( c_Contract[i] != NULL )
{c_Contract[i]->display();}
else
{cout<<endl<<"No Contract for ProdIndex: "<<i;}
}
}
Probably something funny is going on while assigning the contracts under the c_Contracts variable. Please help.