Would someone please explain to me why I get an “Error: not declared in this scope?”
num and denom are private members of class Rationalnumber.
Thanks!
Rationalnumber::Rationalnumber(){
num = 0;
denom = 1;
int * n = new int;
int * d = new int;
*n = num;
*d = denom;
}
Rationalnumber::~Rationalnumber(){
delete n;
}
Is
na member of the class? If not, then it will give error, asnis neither declared in the destructor, nor is it a member of the class.You’ve declared
nin the constructor however, but that is local to the constructor only.The destructor (or any other function) cannot access that variable (which is declared in another function or constructor).