Solved

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

Posted on 2006-06-12
4
296 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
[X]
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
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

615 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