 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Magcialking Guest
|
Posted: Wed Aug 30, 2006 8:24 am Post subject: how to deal with arrays with unknown length? |
|
|
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
|
Posted: Wed Aug 30, 2006 9:03 am Post subject: Re: how to deal with arrays with unknown length? |
|
|
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
|
Posted: Wed Aug 30, 2006 9:11 am Post subject: Re: how to deal with arrays with unknown length? |
|
|
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
|
Posted: Thu Aug 31, 2006 9:10 am Post subject: Re: how to deal with arrays with unknown length? |
|
|
| 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 |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|