Passing objects by ref

Hi and thanks for any help!

I am trying to pass an array of objects but when I use by ref it wont compile. I know it's probably simple syntax but that's why I'm in beginners.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "stdafx.h"
#include "invoice.h"

using namespace std;

void selectionSort(Invoice invoices[], int SIZE);

int main()
{
	const int SIZE = 8;
	int in;

	 Invoice invoices[] = {
	 Invoice( 83, "El", 7, 57.98),
         Invoice( 24, "P", 18, 99.99),
         Invoice( 7, "Sl", 11, 21.5),
         Invoice( 77, "H", 76, 11.99),
         Invoice( 39, "L", 3, 79.5),
         Invoice( 68, "Sc", 106, 6.99),
         Invoice( 56, "J", 21, 11),
         Invoice( 3, "W", 34, 7.5) };

		 selectionSort(invoices, SIZE);

		 cin >> in ;

	return 0;
} 

void selectionSort(Invoice invoice[], int size)
	{

		int start, minIndex;

		string minValue;

	for(start = 0; start <  (size - 1); start++)
	{
		minIndex = start;
		minValue = invoice[start].getDesc(); 

		for(int index = start + 1; index < size; index++)
		{
			if (invoice[index].getDesc() < minValue)
			{
				minValue = invoice[index].getDesc();
				minIndex = index;
			}
		}
		invoice[minIndex].getDesc() = invoice[start].getDesc();
		invoice[start].getDesc() = minValue;
	}

	for (int i = 0; i < size; i++)
		 {
		 cout << setprecision(4) << " " << invoice[i].getPart() <<  " " << invoice[i].getDesc() << " " << invoice[i].getQuant() << " " <<  invoice[i].getPri() << '\n';
		 }

	}
Last edited on
closed account (Dy7SLyTq)
what errors are you getting?
Error 2 error C2664: 'selectionSort' : cannot convert parameter 1 from 'Invoice [8]' to 'Invoice *[]'

Error 1 error C2234: 'invoice' : arrays of references are illegal

Error 12 error C2228: left of '.getQuant' must have class/struct/union (x10)



can you post Invoice.h, also the version of code that fails, i.e what exactly is meant by "when I use by ref"
Topic archived. No new replies allowed.