2D array pointer as function argument

Started by
4 comments, last by moetman 18 years, 8 months ago
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 ?
Advertisement
I think you want void generateTerrain( double pHeightMap[][MAP_SIZE] ) and terrain->generateTerrain( heightField );
generateTerrain1 and generateTerrain aren't the same thing. ;)
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Also, isn't it possible to just have a (double* pHeightTerrain) istead of having the brackets in their?
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
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
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

This topic is closed to new replies.

Advertisement