How to create a 2 dimension array 
Author Message
 How to create a 2 dimension array

 Hi, all;
I type following code to create my 2 dimension CArray, but compile
failed:
...
CStringArray h_sl_routine;
 CArray<CStringArray,int>sl_routine;
...
where is my fault?
Could you should me the correct way?
Thanks a lot
HJ


Tue, 04 Dec 2001 03:00:00 GMT  
 How to create a 2 dimension array

Quote:

> Hi, all;
>I type following code to create my 2 dimension CArray, but compile
>failed:
>...
>CStringArray h_sl_routine;
> CArray<CStringArray,int>sl_routine;
>...
>where is my fault?
>Could you should me the correct way?

     You seem to be a bit confused about how ARG_TYPE--the second parameter to
the CArray template--is supposed to work.  The documentation says that this
is a "Template parameter specifying the argument type used to access objects
stored in the array."  Many people read that, think "Okay, that's the sort of
variable that people will use to specify indexes into the array", and choose
int or some other numeric variable.  But that's not what they mean by "used to
access objects".  The variable type used to specify index into the array is
_always_ an int.  The ARG_TYPE is the type that's used to add and set elements
in the array; in other words, when people call SetElement or InsertAt or
whatever, what should they have to supply?  Usually, if you're keeping an
array of a very simple data type (like int's or float's or whatever), the
ARG_TYPE should be the same as the TYPE; if you're keeping a more complex
data type (like structures or objects), the ARG_TYPE should be a reference
to the TYPE.  Since CStringArray is a pretty darn complex data type, you want
"CArray<CStringArray,CStringArray &>sl_routine;".  
--
\o\ If you're interested in books and stories with transformation themes, \o\
/o/ please have a look at <URL:http://www.halcyon.com/phaedrus>. Thanks!  /o/
\o\   FC1.21:FC(W/C)p6arw A- C->++ D>++ H+ M>+ P R T++++ W** Z+ Sm RLCT   \o\
/o/              a cmn++++$ d e++ f+++ h- i++wf p-- sm#                   /o/


Thu, 06 Dec 2001 03:00:00 GMT  
 How to create a 2 dimension array

Try ths
CArray<CStringArray,CStringArray &>sl_routine

maybe ...

{r=1}r++{r=0}

Quote:

>it isn't possible to use a CArray object as a 2-dimensoined array...

>the class types given to CArray between < and > only specify the return
type
>and the argument type of your CArray object; they often must be the same
>(you can't put integers in your array and then get CStrings out of it !)

>if you urgently need a dynamic 2-dimensoinal array, why not write your own
>one ?? (you just gotta have some experience with templates..)

>see ya,
>peterco



>> Hi, all;
>> I type following code to create my 2 dimension CArray, but compile
>> failed:
>> ...
>> CStringArray h_sl_routine;
>>  CArray<CStringArray,int>sl_routine;
>> ...
>> where is my fault?
>> Could you should me the correct way?
>> Thanks a lot
>> HJ



Sat, 08 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Extending contiguous two dimension array to three dimensions?

2. two dimension array of objects

3. Arrays and Dimensions

4. about the 2-dimension array pointer

5. it is about the 2-dimension array pointer

6. Help with 2D array, fixed 2nd dimension

7. pass a pointer to a multiple dimension array

8. array dimension includes the null character byte also???

9. Re-dimension Array Size in C program

10. modifying dimensions of an array

11. Print one dimension of a multidimensional array...

12. Re-Dimension An Array

 

 
Powered by phpBB® Forum Software