I want to write a function that returns pointer to two-dimensional array of pointers. I have this array: Organism* worldTab[20][20]; and my friend advised to write the function I want in this way:
Organism** getWorldTab() {
return worldTab[20];
}
Is it correct? When I want to do this (temp is Organism*** temp;):
*temp = world.getWorldTab();
Visual Studio throws an exception
Exception thrown: write access violation.
this->temp was 0xCCCCCCCC.
and I am pretty sure getWorldTab()functions is a problem.
worldTab definition: Organism* worldTab[20][20];
worldTab[20]is out of bounds.worldTabdefined?Organism***-- three stars is a sure sign of trouble.worldTab. But it's a bad idea in any case. Usestd::vectorinstead of this horrible low-level pointer management.