Solved

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

Posted on 2006-06-12
4
262 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

912 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now