Is it possible for a derived virtual function to call the virtual function in the base class?

Let's say for example we have a base class and a derived class, the base class has a virtual function that is overridden in the derived class.

Is it somehow possible to call the base virtual function from inside the overridden virtual function in the derived class? if so, how can I call that function?

Please look at the code below to see what I mean...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

//Here is the base class

class BankAccount
{
protected:

    double balance;
    int num_of_deposits;
    int num_of_withdrawals;
    double interest_rate;
    double service_charges;

public:


virtual void Withdraw (double num)
    {
        balance -= num;
        ++num_of_withdrawals;
    }





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

//Here is the derived class

class SavingAccount : public BankAccount
{
    bool status;
    BankAccount *pointer;

public:

    void Withdraw (double num)
    {
        if (balance > 25)
            status == true;

        else
            status == false;

        if (status == true)
            Withdraw (num);              //is this the proper way to call the base class virtual function? or do i need an object to do that?

        else
        {
            cout << "Your account is not active";
            cout << " and therefore you cannot";
            cout << " withdraw any money";
            cout << endl;
        }
    }


p.s program is not complete
Last edited on
19
20
        if (status)
            BankAccount::Withdraw(num); 
Last edited on
Thank you!
Topic archived. No new replies allowed.