Jump to content
  • Advertisement
Sign in to follow this  

Return an array

This topic is 4494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a class a while back that handles creating and using a 2D array. Works like a charm. Latley, I've needed to write the data of the actual array to a file, so I wrote a little function in the class, returnArray, to, well, return a the array. returnArray takes the adress of a temporay array, then copys the array to thes temporary array.
template<class T> void array2D<T>::returnArray(T &destArray)
	for(int i = 0; i< (ARRAY_COLUMNS * ARRAY_ROW); i++)
		destArray = Array;
seems simple enough. Array is of type T btw, aka, it's a templated class. So I then use it like thus:
//create the array to hold that map data.
	array2D<int> tempMapData;
	//3 X 3
	//map tiles
	//set that up
	tempMapData(0,0) = 0;
	tempMapData(0,1) = 1;
	tempMapData(0,2) = 2;

	tempMapData(1,0) = 2;
	tempMapData(1,1) = 1;
	tempMapData(1,2) = 0;

	tempMapData(2,0) = 1;
	tempMapData(2,1) = 1;
	tempMapData(2,2) = 1;

	int *tempArray = new int [tempMapData.retnCol() * tempMapData.retnRow()];


	for(int i = 0; i<9;i++)

Alas, all is not well in programming land. I get a lovely:
e:\programing\directx\nocturne engine\source\nocturne\cmap.cpp(117) : error C2664: 'array2D<T>::returnArray' : cannot convert parameter 1 from 'int *' to 'int &'
soo...I've fiddled, and I'm sleepy, and I have no clue wtf i'm doing wrong. I feel kinda dumb, like I should know this, so please don't be too mean :P Thanks!

Share this post

Link to post
Share on other sites
*smacks head*

Yup, that works. The actual function doesn't actuall work (something is really messed somehwere) but ya, thanks!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!