By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Dynamic 2 dimensional array problem with pointers

P: 3
Hi there

I have a class within which i assign 2 dimension dynamic array of pointers which points to variable inside these class (variable is of type other class).
Now to get into that variable I have to use ptr-> but my ptrtoobj[i][j] is pointer to pointer and left hand side of -> has to be pointer to class/structure
when I use ptrtoobj[i][j]->class_variable I'm getting an error of
type 'cell' does not have an overloaded member 'operator ->' see declaration of 'cell'

Any idea for overloaded function operator-> or to solve these
I know that 1 dimension array would be solution but 2 is easier for calculations for me
Here is code
//constructor and destructor works fine I have tested that
class Game
{
public:
void display();
Game();
Game(int);
virtual ~Game();

private:
int size;
cell **ptrtoobj;
};

Game::Game(int s)
{
size=s;
ptrtoobj=new cell*[size];
for (int i=0; i<size; i++)
{
ptrtoobj[i]= new cell[size];
}

}

Game::~Game()
{
for (int i =0; i<size; i++)
{
delete[] ptrtoobj[i];
}
delete[] ptrtoobj;
}

I sorry for language but English isn't my native language :-)

Regards QryS
Nov 22 '06 #1
Share this Question
Share on Google+
1 Reply


P: 3
language is C++ MS Visual C++
Nov 22 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.