I'm working my way steadily into the C++ stuff and was wondering if the following is OK. (I'm making a clone of tertis for practice with SDL.)
I have a class "Block" which will generate a random colour and create one of 5 random shapes.
I am trying to make a "BlockGenerator" which will act as a list of all blocks on display, add blocks, deal with collisions etc.
I was writing a function to add a block to the display:
Here's an edited header file:
And here's a snippet from the source file:Code:#include "Blocks.h" class BlockGenerator { public: static vector<Block *> blockList; int indexOfCurrentBlock; BlockGenerator(); void addBlock(); };
Code:vector <Block *> BlockGenerator::blockList; BlockGenerator::BlockGenerator() { } void BlockGenerator::addBlock() { Block newBlock; newBlock.onInit(); BlockGenerator::blockList.push_back(&newBlock); }
My question is about the last bit. Because I've declared a new instance of Block within the function, I've got this feeling that this will disappear after the function returns. Should I do this dynamically with 'new' or is this fine.
Thanks in advance



LinkBack URL
About LinkBacks


