Advertisement Jump to content
Sign in to follow this  
moetman

2D array pointer as function argument

This topic is 4898 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

in main: double heightField[MAP_SIZE][MAP_SIZE]; Terrain *terrain = new Terrain(); terrain->generateTerrain( &heightField ); in Terrain: //function sig void Terrain::generateTerrain1( double *pHeightMap[][MAP_SIZE] ) Display.cpp: In member function `int Display::update_display()': Display.cpp:1112: error: no matching function for call to `Terrain::generateTerrain1(double (*)[512][512])' Terrain.cpp:58: note: candidates are: void Terrain::generateTerrain1(double* (*)[512]) make: *** [Display] Error 1 Why doesn't it like it ?

Share this post


Link to post
Share on other sites
Advertisement
I think you want void generateTerrain( double pHeightMap[][MAP_SIZE] ) and terrain->generateTerrain( heightField );

Share this post


Link to post
Share on other sites
Alternatively you could use std::vector
std::vector< std::vector< double > > heightField;

// or like this (I personally find it more readable, but that might just be me)
std::vector<std::vector<double> > heightField;


There's also an interesting thread about 2D arrays in C++ here There's also some discussion about boost::multi_array in that thread as well

Share this post


Link to post
Share on other sites
Thanks Guys,

I'll try when I get home,
So you can have a pointer to a 2d array ? someFunc(double *ptr) that will take a N-dim array ?
Aren't 2d arrays really 1d anyway

Thanks again

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!