| | |
passing arrays / updating object arrays
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
C++ Syntax (Toggle Plain Text)
toppings[z] = a[z] ;
C++ Syntax (Toggle Plain Text)
void Pizza::set ( int x , int y , int a[] , int i );
C++ Syntax (Toggle Plain Text)
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] ; }
C++ Syntax (Toggle Plain Text)
pizza.set ( x , y , a, i ) ;
The truth does not change according to our ability to stomach it.
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!!
Now I just need to do some slight modifications and add the computePrice function and I'm done.
thanks everyone!!
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.
-Edsger Dijkstra
-Edsger Dijkstra
I thought you had declared the third parameter as a reference to an array?
C++ Syntax (Toggle Plain Text)
void Pizza::set ( int x , int y , int (&a)[7] , int i )
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
i did but then i found out that c++ passes all arrays by reference by default.
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. C++ Syntax (Toggle Plain Text)
void Pizza::set ( int x , int y , int (&a)[7] , int i )
C++ Syntax (Toggle Plain Text)
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 )
Last edited by Hamrick; Sep 6th, 2007 at 10:20 pm.
The truth does not change according to our ability to stomach it.
The answer depends on the current code.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
That's a pointer (see #35).
http://c-faq.com/aryptr/aryptrparam.html
http://c-faq.com/aryptr/aryptrparam.html
Last edited by Dave Sinkula; Sep 7th, 2007 at 12:33 am.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Passing arrays between subs (VB.NET)
- Help: Passing arrays between functions (C)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Passing Arrays of Objects to Member Functions (C++)
- passing arrays to classes? (Java)
- Arrays (C++)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Declaring a list in a header file
- Next Thread: Dynamic array
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






