debugging a sorted list program

I'm getting compilation errors relating to my list constructor and I'm not sure what's wrong. In defense of the rest of it, my teacher is probably the worst I've had in any subject ever - no exaggeration - and I'm practically self-taught. I've been trying to learn classes(hence trying to use it) and had a homework problem using sorted lists. I've gotten in a bad habit of trying stuff I don't know will work then spending extra time debugging, as for any dumber errors.
I need to print an array then sort it in ascending order once with a bubble sort and once with a selection sort. Thanks in advance!
Here's the error:
error: request for member âprintâ in âSortâ, which is of non-class type âList()â

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
60
61
62
  #include <iostream>

using namespace std;

const int SIZE = 8;
int array[] = {8, 256, 16, 64, 2, 4, 128, 32};

class List
{
public:
   List();
   void print()
   {
      for(int i = 0; i < SIZE; i++)
      {
         cout << array[i] << ", ";
      }
         cout << endl;
   };
   void bubble()
   {
      for(int i = 0; i < 8; ++i) //pre-increment?
      {
         for(int j = 0; j < (8 - i); ++j)
         {
            int swap = array[j];
            array[j] = array[j+1];
            array[j+1] = swap;
         }
      }
   };
   void select()
   {
      for(int i = 0; i <= SIZE - 1; i++) // might need to make size - 2 bcuz \0
      {
         int min = i; //minimum value of the array
         for(int j = (i + 1); j < SIZE; j++)
         {
            if(array[j] < array[min])
            {
               min = j;
            }
            int swap = array[i];
            array[i] = array[min];
            array[min] = swap; //not sure of the reason for the redundancy
         }
      }
   };
};

int main()
{
   List Sort();

   cout << "The unsorted list is: " << Sort.print();
   cout << "The list ordered with a selection sort is: " << Sort.print.select();
   cout << "The unsorted list again: " << Sort.print();
   cout << "The list ordered with a bubble sort is: " << Sort.print.bubble();

return 0;
}


I posted this a little while ago, but it wasn't formatted properly. I've tinkered with some things since then, but I'd like opinions on this version first.
Last edited on
The most obvious problem I missed was trying to call a void function to cout. I was having the same error messages when called separately though. I was told the dot notation here was wrong, but I saw it in my book like this once before.
Topic archived. No new replies allowed.