•      Sign In
• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #ActualBitMaster

Posted 01 August 2012 - 04:03 AM

Neither of the two versions should be compiling. getVector() returns a pointer to the vector (so you would need return &vector; in the first place unless your vector was a pointer - which it should not have to be and in general would indicate a design problem).
setVector() instead expects a reference but the assignment "vector<Classname*> vectorToSend = pointerToClass->getVector();" should not compile.
pointerToClass->setVector(pointerToAnotherClass->getVector());
should compile fine if getVector() returned a reference or setVector accepted a pointer. Of course
pointerToClass->setVector(*pointerToAnotherClass->getVector());
would work without further change but I'm not a fan of using pointers and references interchangeably unless there is a good semantic reason for it (which I cannot see here).

On a sidenote, saying "for some reason, this code is invalid" is not helpful. The compiler (or linker) produces an error message which should have been posted.

### #1BitMaster

Posted 01 August 2012 - 04:01 AM

Neither of the two versions should be compiling. getVector() returns a pointer to the vector (so you would need return &vector; in the first place unless your vector was a pointer - which it should not have to be and in general would indicate a design problem).
setVector() instead expects a reference but the assignment "vector<Classname*> vectorToSend = pointerToClass->getVector();" should not compile.
pointerToClass->setVector(pointerToAnotherClass->getVector());
should compile fine if getVector() returned a reference or setVector accepted a pointer.

On a sidenote, saying "for some reason, this code is invalid" is not helpful. The compiler (or linker) produces an error message which should have been posted.

PARTNERS