I’m currently coding on a project and I have a function that looks like this:
Room::addItem(Item*&); //not written by me
I have some trouble understanding what to send as parameter.. the “*&” mess it up for me.
I’ve tried the following:
foo.addItem(loadItem()); //Returns an Item-object
/*and*/
foo.addItem(loadItem()); //Returns an Item-pointer
edit: It would be nice if you explain what the “*&” means. I want to understand it next time I run in to it 😉
The
addItemfunction accepts argument of typeItem*and the pointer is passed by reference. It means that the functionaddItemcan modify the pointer internally. This may also imply that the object is being reallocated or modified inside this function.Example:
Pointer By Reference are only valid in C++.