C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to deal with arrays with unknown length?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Magcialking
Guest





PostPosted: Wed Aug 30, 2006 8:24 am    Post subject: how to deal with arrays with unknown length? Reply with quote



for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b's length remains unkown, so what can I
do?
Back to top
David Harmon
Guest





PostPosted: Wed Aug 30, 2006 9:03 am    Post subject: Re: how to deal with arrays with unknown length? Reply with quote



On 29 Aug 2006 20:24:29 -0700 in comp.lang.c++, "Magcialking"
<magic_king (AT) 163 (DOT) com> wrote,
Quote:
for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b's length remains unkown, so what can I
do?

Write it in C++ instead of C.
Avoid bare naked arrays.
You might end up with something like:
int a(std::vector<int> & b)

Otherwise, you have to pass the number of elements as an additional
argument, or something.
Back to top
red floyd
Guest





PostPosted: Wed Aug 30, 2006 9:11 am    Post subject: Re: how to deal with arrays with unknown length? Reply with quote



David Harmon wrote:
Quote:
On 29 Aug 2006 20:24:29 -0700 in comp.lang.c++, "Magcialking"
magic_king (AT) 163 (DOT) com> wrote,
for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b's length remains unkown, so what can I
do?

Write it in C++ instead of C.
Avoid bare naked arrays.
You might end up with something like:
int a(std::vector<int> & b)

Otherwise, you have to pass the number of elements as an additional
argument, or something.


Not to mention writing in C++ instead of Java.
Back to top
Gernot Frisch
Guest





PostPosted: Thu Aug 31, 2006 9:10 am    Post subject: Re: how to deal with arrays with unknown length? Reply with quote

Quote:
void Func_BehindTheCurtains(int *p,size_t len) {}

, and then invoke it using the following:

template<size_t len
void Func(int (&arr)[len])
{
return Func_BehindTheCurtains(arr,len);
}


int* pA = new int[128];
Func(pA);

???
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.