Inheritance

I don't understand how inheritance works entirely. I'm trying to make a program that counts the number of comparisons that a sort makes using a virtual class but I'm getting the error "cannot declare variable 'q' to be of abstract type 'childsort'. and I don't understand why I can't declare that variable.

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
class AbstractSort
{
protected :
    int conversions;

public :
    AbstractSort(){};

    void setConversions(int c)
    { conversions = c; }

    int getConversions() const
    { return conversions; }

    int addConversions()
    { return conversions++; }

    virtual void sort(int arr[], int size) const = 0;
};


class childsort : public AbstractSort
{


    public :
        childsort() : AbstractSort(){}

        virtual void sort(int arr[], int size)
        {
            int x = 0, y = 0, c = 0;

            for(x = 0; x < size - 1; ++x)
            {
                for(y = 0; y < size - x - 1; ++y)
                {
                    if(arr[y] > arr[y + 1])
                    {
                        int temp = arr[y];
                        arr[y] = arr[y + 1];
                        arr[y + 1] = temp;
                    }
                setConversions(c++);
                }
            }
        }
};

int main()
{
    childsort q;
}
I think I figured it out but I would like some conformation from someone who knows better. Removing the const tag on line 18 allowed me to create a child class but I'm wondering does that mean you can't edit a child function at all if the parent function is set to const or does that mean you can't edit specific things inside the child function? Or is it some other thing I'm missing?
Topic archived. No new replies allowed.