I tried this and error was
error: invalid use of non-static data member 'A::n'
Why cant we assign data member in method?
#include <iostream>
using namespace std;
class A
{
int n,m;
public:
A()
{
n=5;
m=8;
}
void fun(int a,int b=n)
{
while(b--)
{
cout<<"XYZ";
}
}
};
int main()
{
A obj;
obj.fun(6);
return 0;
}