Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How can I make a Two-Dimension array of classes by operator overloading?

Reply
Thread Tools

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

 
 
adc++
Guest
Posts: n/a
 
      05-10-2006
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?

 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      05-10-2006
adc++ wrote:
> 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

 
Reply With Quote
 
 
 
 
Axter
Guest
Posts: n/a
 
      05-10-2006
adc++ wrote:
> 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/showth...hreadid=297838

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Assigning an array to another array using C's assignment operator Myth__Buster C Programming 13 02-26-2013 04:29 PM
FAQ 5.9 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles? PerlFAQ Server Perl Misc 0 01-12-2011 11:00 PM
Why can nsmc, local classes or anonymous classes have static members? Rit Java 23 01-03-2010 05:54 PM
Can I using reflection to get all child classes or classes undera package dynamically? Carfield Yim Java 1 05-31-2004 05:33 PM



Advertisments