std::vector initialization problem

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
drwbns
Orc Shaman
Posts: 788
Joined: Mon Jan 18, 2010 6:06 pm
Location: Costa Mesa, California
x 24

std::vector initialization problem

Post by drwbns »

Hi guys, I'm trying to initialize a vector like this -

Code: Select all

std::vector<std::vector<hkReal>> *terrainVertices;
terrainVertices->push_back(std::vector<hkReal>());
But I'm just getting a crash in the <vector> cpp file so I'm guessing there's something wrong here. Any thoughts on this one?
Alessan
Gnoblar
Posts: 6
Joined: Tue Jul 15, 2014 12:17 am
x 1

Re: std::vector initialization problem

Post by Alessan »

Hi,

If you use a pointer, you must allocate memory for it.

std::vector<std::vector<hkReal>> *terrainVertices = new std::vector<std::vector<hkReal>>();
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: std::vector initialization problem

Post by dark_sylinc »

And don't forget to delete the memory afterwards.
Post Reply