Passing unknown Array to Function by reference (C++) -


I've spent a great time trying to understand - how do I write this function (at the top of the code - insertionsort ) Which allows me to pass an array from its context. One way is to allow me to call 'size' on the array. This should be an array for this assignment.

I have not tried to pass it through context, delete the array before calling the shape on it, etc. I am getting errors: (.

This is the most recent compiler error for code:

EnterSort. Cpp: 11: Error: Parameter '' A ' Contains the references to the unknown bound array ?? int [] a ???? insertion STPP: zero zero entry in function (int (and) []): Combination code CPP: 13: error : In the shape of the "size" request for the member (int ), which is a non-square type ??? INTream & lt; iostream & gt; // # added - Error here {for (int j = 1; j & lt; = a-> size (); j ++) & lt; ----- error here {int key = a [ja]; // now sorted sequence one [ja] ] Is a [0 ... j-1]. Int i = j-1; while (i> = 0 & amp; a [i] & gt; key) {a + ii] = a [ Ii = ii = 1;} a [i + 1] = key;}} int main () {int Asize = 0; cout & lt; "Hello. \ N Please enter the number value for the inclusion item Size and then press Enter: "& l T; & Lt; Endl; Cin & gt; & Gt; Asize; Int a [Ashes]; Four acupuncture; Cout & lt; & Lt; "Best case \ nw - for the worst case \ n - for the average case" & lt; & Lt; - There are three ways to order Your Institution Sort Orange; Andal & lt; & Lt; "What kind of desire do you want for this array? \ NPlease 'b', 'w', or 'a':" & lt; & Lt; Endl; Cin & gt; & Gt; A type; If (ATP == 'B') {cout & lt; & Lt; "You have chosen type B." & Lt; & Lt; Endl; } And if (Atype == 'w') {cout & lt; & Lt; "You have chosen type Y." & Lt; & Lt; Endl; } And if (ATP == 'A') {cout & lt; & Lt; "You have selected one type." & Lt; & Lt; Endl; } cout & lt; & Lt; "End Program" & lt; & Lt; Endl; It is important to remember that the array array is only the first element of the array array. It is easy to pass the array, you can do something like this:

  void foo (int * array)   

or

  void foo (int array [])   

However, since this is only an indicator of the base type, there is no member function to call it and there is no clue It is beyond what the memory structure looks like (i.e. there is no concept of length) If you wanted to know the length of a dynamic array that was passed to you, then you need to pass the length in the form of the second parameter, possibly the length of the array that has been created should be known.

  void foo (int * array, unsigned integer length)   

Or, you can avoid all this and use vectors which are Java Are similar to an ArrayList.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -