Jayakumar
Jayakumar

Reputation: 155

Access specifier, not able to call a function which is defined in the derived class

I tried to learn about the access specifier in c++, So i access a public and protected member from the base class and performed a add function in the derived class as shown below,

#include<iostream>
using namespace std;

class Base
{
    public:
        int a;
    protected:
        int b;
};

class Derived : public Base
{
    public:
        int sum;
        void add()
        {   
            a = 10;
            b = 20;
            sum = a + b;
        }
};


int main()
{
    Derived Obj;
    Obj.add;
    cout << "The sum : " << Obj.sum << "\n";
    return 0;
}   

But while compile i get the following error message "statement cannot resolve address of the overload function" can anyone explain what is the error?

Thanks in advance

Upvotes: 1

Views: 41

Answers (1)

P.W
P.W

Reputation: 26800

The function call is missing parenthesis in the following line:

Obj.add;

It should be: Obj.add();

Upvotes: 2

Related Questions