Solved

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

Posted on 2006-06-12
4
275 Views
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]
0
Comment
Question by:oxygen_728
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
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;
0
 

Author Comment

by:oxygen_728
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
0
 
LVL 12

Expert Comment

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

Expert Comment

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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embarcadero C++ Builder XE2 TDateTime 8 70
White board coding practice 3 86
Problem with SqlConnection 4 168
Embarcadero C++ Builder XE10.1 Berlin red arrow Indicator 2 34
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

786 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