jeudi 20 avril 2017

setting object variables inside function

I've been trying to set variables for a class inside a outside function; I think that this ends up erasing the class after the function exits, if this is true, what are ways around it?

Book bookArray[lineIndex];    
bookArray[0].setTitle("Here!");

//function in loop called in main
for (int i = 0; i<lineIndex; i++)
{
    arrayToBook(tempArray, bookArray[i]);
}

cout << bookArray[0].getTitle() << endl;
//returns empty space

//function definition
void arrayToBook(string* tempArray, Book bookIn)
{
    bookIn.setTitle(tempArray[0]);
    bookIn.setAuthor(tempArray[1]);
    //other sets
}






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire