1
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 ) ;
Votes + Comments
great suggetion!
0

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!!

0

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 )
0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.