Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is has to be possible!

Status
Not open for further replies.

EngineersForge

Technical User
Aug 26, 2003
15
CA
I cannot set a pointer to a multi-dementional array such as:

const string sTable[ROWS][COLUMNS];

trying:

string sp* = &sTable;

does not work.

trying:

string &sr = sTable;

does not work.

I have attempted different loops using the new operator to no success also.

Is their not a way to create a inderect access to a multi-dementional array of string objects???

If so, please tell me. It will make many things much simpler for me.

Many tanx.

 
did you try:

string* ps=&sTable[0][0]; ??

Greetings,
Rick
 
Yes that works. It seems obvious now. Set the pointer to the zero columm and zero row. Of course, now the question is, how do you access the strings with the pointer? More to the point, what does the array look like in memory with
COLUMN = 15
ROW = 30

tanx
 
I have no idea...
I never work with strings, but if I'm not mistaken, they're just a wrapper class around (t)char*'s. So the memory layout there would probably the layout of a normal instance of that class and if you want to access member variables/functions of the class at column15/row30 i think you should have the pointer point to that "cell", instead of 0/0 and start working with the pointer.

Greetings,
Rick
 
Arrays in C++ are stored 'row-wise' (last subscript varies fastest) and the first subscript in the declaration helps determine the amount of storage consumed by an array but plays no other part in subscript calculations.

So, for example,if you have char x[3][5] then when x appears in an expression it is converted to a pointer to (the first of three) five membered arrays of characters.

So, the expression x (or *(x+i)) yields a pointer to the first of an array of characters, that array being indexed from i.

 
sorry - that should read....

the expression x[j] (or *(x+j)) yields a pointer to the first of an array of characters, that array being indexed from j.

replacing j with i put the rest of the sentence in italics :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top