Array of Pointers - Indexing the array as a multidimensional array - Question

Posted on 2006-06-12
Last Modified: 2012-05-05
AStruct* P[500];

cout << P[5][10]->astring <<endl;

Please tell me if I am correct.

This does not work because the compilers sees that P is an array of pointers.
So, the compiler processes the first bracker [5] and determines which pointer to 'use'
When it encounters the [10], it assumes that it is now dealing with the 10th memory offset of pointer AStruct, which should lead to some bad memory access issues.

I'm just trying to confirm some of my suspicions.

I'm also curious if it is possible to access an array of pointers via brackets as a multidimensional array.

It's a bit annoying to have to do a P[5 * RowLength + 10]
Question by:oxygen_728
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 12

Accepted Solution

rajeev_devin earned 500 total points
ID: 16883934
>> cout << P[5][10]->astring <<endl;

It should be like this
cout << P[5][10].astring << endl;

Author Comment

ID: 16883971
I had some implementation issues, i thought you could do what I was doing above.

Thanks for the tips in this post and the previous
LVL 12

Expert Comment

ID: 16883974
>> I'm also curious if it is possible to access an array of pointers via brackets as a multidimensional array.
LVL 12

Expert Comment

ID: 16883981
>> Thanks for the tips in this post and the previous
my pleasure :)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing the elements of a set declared inside a map in C++. 3 69
C++ Code Issue 4 48
c++  placing data into a form and an editbox 5 50
using interface in TLB 3 31
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question