How can I make a Two-Dimension array of classes by operator overloading?

A

adc++

Hi
Imagine that I have two classes one columns and one rows.
I want to can call a class-pointer that is in the rows with this call:
man [5][4]
how can I do it?
I know that I must overload [] but this have two dimensions. How can I
do it?
 
J

Jonathan Mcdougall

adc++ said:
Hi
Imagine that I have two classes one columns and one rows.
I want to can call a class-pointer that is in the rows with this call:
man [5][4]
how can I do it?
I know that I must overload [] but this have two dimensions. How can I
do it?

Funny, two identical questions in 10 minutes.

This is a FAQ: http://www.parashift.com/c++-faq-lite/.


Jonathan
 
A

Axter

adc++ said:
Hi
Imagine that I have two classes one columns and one rows.
I want to can call a class-pointer that is in the rows with this call:
man [5][4]
how can I do it?
I know that I must overload [] but this have two dimensions. How can I
do it?

I recommend against using the method posted in the C++ FAQ.
It recommends you use a non-standard syntax.

If you want to use standard syntax check out the following link for an
example:
http://code.axter.com/dynamic_2d_array.h

However, for most requirements, I recommend using a vector of vector.
Example:
int col = 123;
int row = 456;
vector<vector<int> > My2dArray(col, vector<int>(row));


You can reference both the above vector code and the dynamic_2d_array
class using double index ([][])
My2dArray[0][0] = 99;

Check out the following link for wrapper classes using vector of
vector:
http://www.codeguru.com/forum/showthread.php?t=231046
http://www.codeguru.com/forum/showthread.php?s=&threadid=297838
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top