I am well aware that line 7 is invalid . but I want to use the class variables as default argument to method(apple) .
class trial{
public:
int i=10 ;
void apple(int i=this.i){
cout<<i<<endl;
}
void display(){
cout<<i<<endl;
}
};
Replace
void apple(int i=this.i){
cout<<i<<endl;
}
… with
void apple(int i){
cout<<i<<endl;
}
void apple(){
apple(i);
}
You can't access member variables in the formal argument list of a function.