I've written a simple class given below. I had set the values through setab() function but the add()function didn't work. Compiler shows CPP/class.cpp|20|error: ‘int Calc::add()’ is private|
#include <iostream>
usingnamespace std;
class Calc
{
int a, b;
int add();
public:
void setab(int num1, int num2);
};
void Calc::setab(int num1, int num2)
{
a=num1;
b=num2;
}
int Calc::add()
{
return a+b;
}
int main ()
{
Calc sum;
sum.setab(5,6);
cout<<sum.add()<<endl;
return 0;
}