hey folks, i have a problem which seems to be reasonably simple but i havnt managed to figure it out yet. Iv read alot of the other threads on this but i still havnt found one that iv both understood and solved my problem. So here goes...

Its concerning returning a member variable, that is a 2d array made within a class, to the program.

//located in the class header file
int**	m_iPopulation;

//located in the class constructor
m_iPopulation = new int* [m_iPopDensity];
for(unsigned short int i=0; i<m_iPopDensity; i++)
	m_iPopulation[i] = new int [m_iChromeLength + 4];

the above all works fine, i can see the population when i fill the array and i can print them to the screen etc. The problem comes when i try to return the above array to the main program.

//located in class header file
inline int**	GetPopulation(){return m_iPopulation;};

//located in the main() program
int** iPopulation = new int* [iPopDensity];
for(unsigned short int i=0; i<iPopDensity; i++)
	iPopulation[i] = new int [iChromeLength + 4];

iPopulation = _pGA->GetPopulation();

when i try to print whats in the array all i get is 1 memory address. and when i debug all i can see is a single entry in the array.

not sure what im doing wrong and i cant find anything else on the fora to help me, so any help is greatly appriciated.

thx!

Recommended Answers

All 3 Replies

You'll have to show us your output statement(s). It's likely that you are not de-referencing the pointer(s) properly...

Removed**

Said something stupid :/

ahh im total retard. the memory address i thought it was returning wasnt it was a massive negative value because i didnt assign a value to the place in the array that i was trying to pring.

the return code works fine just me being stupid.

thanks for the help anyway guys, ill be sure to check through my work more thoughly next time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.