samedi 14 mars 2015

Setting derived classes items through base class variable



class Music: public mediaInfo
{
public:
std::string strProducer;
float fMinutes;

void setProducer(std::string strMusicProducer);

std::string getProducer() {return strProducer;}
};


//////////////////////////////////////////////////// //Switch statement within main



case 'F':
{
std::string strMusicProducer;
inputCharacter.erase(0,1);
std::cout << "Enter Producer of music item: ";
getline(std::cin, strMusicProducer);
aMixedArray[nInItIncreaser]->setProducer(strMusicProducer);
}


///////////// //Creating new items



int init_mixed_array()
{



for (int nInItIncreaser = 0; nInItIncreaser < MAX_INIT_ARRAY_SIZE; ++nInItIncreaser)
{
int nInItType = (nInItIncreaser / PER_GROUP);
std:: cout << nInItType << std::endl;
switch (nInItType)
{
case 0 :
aMixedArray[nInItIncreaser] = new Book();
break;

case 1 :
aMixedArray[nInItIncreaser] = new Music();
break;

case 2 :
aMixedArray[nInItIncreaser] = new Video();
break;

case 3 :
aMixedArray[nInItIncreaser] = new mediaInfo();
break;

default :
std::cout << std::endl << "Error" << std::endl;
}
}//end of for loop
return 0;


The mixed array is creating new books, music, media items, and videos. The problem i'm having is assigning the producer within the music derived class.




Aucun commentaire:

Enregistrer un commentaire