Re: passing arrays / updating object arrays 80 80
toppings[z] = a[z] ;

If a is declared as a plain int, why are you subscripting it like an array of int? I think you should make the whole thing an array and that'll fix your problem.

void Pizza::set ( int x , int y , int a[] , int i );
void Pizza::set ( int x , int y , int a[] , int i )
{
    type = x ;
    size = y ;
    for ( int z = 0 ; z < i ; z++ )
        toppings[z] = a[z] ;
}
pizza.set ( x , y , a, i ) ;
Duki commented: great suggetion! +4
Re: passing arrays / updating object arrays 80 80

awesome!! It's working now!
Now I just need to do some slight modifications and add the computePrice function and I'm done.

thanks everyone!!

Re: passing arrays / updating object arrays 80 80

I thought you had declared the third parameter as a reference to an array?

void Pizza::set ( int x , int y , int (&a)[7] , int i )
Re: passing arrays / updating object arrays 80 80

i did but then i found out that c++ passes all arrays by reference by default.

Re: passing arrays / updating object arrays 80 80

i did but then i found out that c++ passes all arrays by reference by default.

You have to be careful here. 'By reference' could mean two things, and only one of them is right. ;) Thef irst by reference is an actual reference in C++ and arrays are not passed by that reference by default. To pass an array by actual reference in C++ you do it like Dave said.

void Pizza::set ( int x , int y , int (&a)[7] , int i )

The second by reference is a fake reference that you get by passing a pointer by value and being able to get to the thing that the pointer points to. That's the default for arrays and that's why all of these are the same prototype.

void Pizza::set ( int x , int y , int a[7] , int i )
void Pizza::set ( int x , int y , int a[] , int i )
void Pizza::set ( int x , int y , int *a , int i )

Woohoo! Finally something I know something about. :D

Re: passing arrays / updating object arrays 80 80

ah ok. so did i create a pointer?

Re: passing arrays / updating object arrays 80 80

The answer depends on the current code.

Re: passing arrays / updating object arrays 80 80

it's the same as post #31.

Re: passing arrays / updating object arrays 80 80

That's a pointer (see #35).
http://c-faq.com/aryptr/aryptrparam.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.