Virtual classes

Any idea why my ptr1 doesnt work on line 41 thats were i get the error.
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
#include <iostream>
#include <string>

using namespace std;

class alpha{
protected:
    int width, height;
public:
    alpha(int a, int b){
        width = a;
        height = b;
    };
    virtual int add(int a, int b)=0;
    virtual int sub(int a, int b)=0;
    virtual void print();
};

class beta : public alpha
{
public:
    int cadd, csub;
    beta(int a, int b) : alpha(a, b){}
    int add(){
        cadd = width + height;
        return cadd;
    }
    int sub(int a, int b){
        csub = width - height;
        return csub;
    }
    void print(){
        cout << "Add gives: " << cadd;
        cout << "Subtract gives: " << csub;
    }
};


int main()
{
    alpha * ptr1 = new beta;
    ptr1 -> add(6,9);
    ptr1 -> sub(6,9);
    ptr1 -> print();
    
    system("pause");
    return 0;
}
Because beta's add is not overrideing alpha's. Look at the arguments.
Topic archived. No new replies allowed.