--- In [email protected], Thomas Hruska <thru...@...> wrote:
>
> > Hi All,
> > 
> > While dealing with functions in C++ .
> > Is ther any way to pass the arrays  to the functions by value rather than 
> > reference?
> > 
> Templates can be passed by value.  Using std::vector<> or Block<> would 
> do the trick.
> 
> However, depending on use, you may also consider doing a 'const &', 
> which passes by reference but is read-only.

You can also cheat by enclosing the array in a structure, and passing the 
structure by value. Eg. (sorry, in C) instead of:

    void processValues(int v[]);

    int values[5] = {3, 8, 10, 14, 18};

    processValues(values); /* pass by reference */

use:

    typedef struct {
        int a[5];
    } Values_t;

    void processValues(Values_t v);

    Values_t values = {{3, 8, 10, 14, 18}};

    processValues(values); /* pass by value */


Reply via email to